Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How do I display a decimal value to 2 decimal places?

While showing the value of a decimal presently with .ToString(), it's accurate to like 15 decimal places, and since I'm utilizing it to represent dollars and cents, I just need the yield to be 2 decimal places.

Do I utilize a variety of .ToString() for this?
by

2 Answers

akshay1995

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

or

decimalVar.ToString ("0.##"); // returns "0" when decimalVar == 0
Govind01xij
use .toFixed(2) instead of ToString

example: decimalVar.toFixed (2);

Login / Signup to Answer the Question.