Solved

Convert decimal to string C#

Posted on 2013-06-18
2
744 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 300 total points
ID: 39256256
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
ID: 39256392
Just what I needed.

Thanks
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Google Maps with Webforms 1 30
Upgrade code from VS 2010 to VS 2015 7 34
How to force output to ascii 2 41
Check only one toolstripmenu item 12 31
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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