Alex Rivera | Logout

How to limit a decimal number?

Asked 2010-07-09T12:20:53.253
32

Possible Duplicate:
How to format a decimal

How can I limit my decimal number so I'll get only 3 digits after the point?

e.g  2.774
Edit
Report

1 Answer

8

To get Decimal back use Math.Round with Second parameter specifying number of decimal points.

decimal d = 54.9700M;    
decimal f = (Math.Round(d, 2)); // 54.97

To Get String representation of number use .ToString() Specifiying Decimal Points as N3. Where 3 is the decimal points

decimal d = 54.9700M;    
string s = number.ToString("N3"); // "54.97"
answered 2010-07-09T12:27:51.783

Your Answer