Thursday, January 31, 2019

c# - How do I round a decimal value to 2 decimal places (for output on a page)



When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.



Do I use a variation of .ToString() for this?



Answer



decimalVar.ToString ("#.##"); // returns "" when decimalVar == 0


or



decimalVar.ToString ("0.##"); // returns "0"  when decimalVar == 0

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...