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
Solved

Convert decimal to string C#

Posted on 2013-06-18
2
730 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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
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…

808 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