0

Possible Duplicate:
Math.Round not keeping the trailing zero
How to round double values but keep trailing zeros

I have a decimal that I want to round to 2 dp. So, I have used Math.Round(). When I have a number like this

23.126

I get the format that I want

23.13

But when I have something like this

23

I get

23

What I'd like is to always get 2 dp. So, in the previous example I'd like

23.00

If I have

23.1

I'd like

23.10

Any idea how I might do this?

Community
  • 1
  • 1
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304
  • If you declare a decimal with decimal places, it will be displayed with the same number of decimal places: `decimal d = 23.00m;`. http://ideone.com/NJRXUq – Tim Schmelter Jan 03 '13 at 16:29

1 Answers1

2

Then you don't want to round the value, you want to format it into a string.

string formatted = value.ToString("N2");
Guffa
  • 687,336
  • 108
  • 737
  • 1,005