Sunday, August 7, 2011

Rounding Number in C#


Below are samples of rounding in C#:

decimal value=12.234;
decimal RoundedValue=decimal.Round(value,2);

Ans: RoundedValue=12.23

If we want to represent 100 like 100.00 by above sample then its not possible. There is another way to represent:

value=100;
decimal RoundedValue=Convert.ToDecimal(value.ToString("F"));

Ans: RoundedValue=100.00

No comments:

Post a Comment