Solved

Convert decimal to string C#

Posted on 2013-06-18
2
702 Views
Last Modified: 2013-06-18
I have a decimal variable that I need to convert to a string  that has only 2 decimal places.

Convert 25.69624953583364277757148162

To "25.69"

What is the c# expression?

Thanks
0
Comment
Question by:Dovberman
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 300 total points
Comment Utility
Hi.

If you have a decimal variable, you can use the ToString() method.
MSDN: http://msdn.microsoft.com/en-us/library/0b22a4x2.aspx

It uses the standard numeric format codes.
MSDN: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
Just pick the format that matches your intended use. For example, ToString("C2"), ToString("F2"), or ToString("N2") where the 2 represents the number of decimal places.
0
 

Author Closing Comment

by:Dovberman
Comment Utility
Just what I needed.

Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using MS Code on my Mac 6 44
windbg taking it's time 32 49
Limiting string to two deciamls 18 30
How to open a link from vb.net app 3 8
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now