Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: Decimal to rounded string

If I have a decimal, how do I get a string version of it with two decimal places? This isn't working:

Math.Round(myDecimal, 2).ToString("{0.00}");
like image 533
JamesBrownIsDead Avatar asked Dec 29 '22 04:12

JamesBrownIsDead


1 Answers

Don't use the curly brackets, they are for embedding a formatted value in a longer string using string.Format. Use this:

myDecimal.ToString("0.00");
like image 84
David M Avatar answered Dec 31 '22 18:12

David M