How to display two digits after decimal every time using C#?
22,972
Solution 1
try
double num=17.2;
string str=num.toString("0.00");
or this one.
double num=17.2;
string str=num.toString("N2");
Solution 2
Try This:
double d=23.45;//any value here
String s=d.ToString("N2");
Author by
Ram Singh
learn learn and learn as much as you can dude..... because learning could never be end up.
Updated on February 21, 2020Comments
-
Ram Singh about 4 years
I have a process, in which client want me to always display amount with two decimals either have value with decimal or not
example: if 17 then i want to display "17.00" and if 17.2 then i want to display "17.20" or if 17.2033 then i want to display "17.20" i have tried
String.Format("{0:.##}", rec.Rate)
it does not works, please help me how can i do it.. thanks in advance
-
devnull69 about 10 yearsWhat about
String.Format("{0:0.00}", rec.Rate)
? -
Hunter Mitchell about 10 yearsPlease check out this similar answer: stackoverflow.com/questions/1291483/…
-