[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1030
  • Last Modified:

Convert decimal to string C#

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
Dovberman
Asked:
Dovberman
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
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
 
DovbermanAuthor Commented:
Just what I needed.

Thanks
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now