0

How to round a double variable to 0,00?

when i use Math.Round(n, 2) if n is for example 1.20 and i use Console.WriteLine(n) it shows 1.2 is there a way to show it 1.20

19th Jan 2017, 2:35 PM
GeorgeSabev
2 Answers
+ 2
you need to use string formatter: double d =1.2; console.writeline(d.ToString("#.00")); or: console.WriteLine("{0:#.00}", d); both of these print 1.20
19th Jan 2017, 4:21 PM
HAL8999++;
HAL8999++; - avatar
0
double d = 1.275; Math.Round(d, 2); // 1.27 Math.Round((decimal)d, 2); // 1.28
19th Jan 2017, 3:46 PM
Josh Luwang
Josh Luwang - avatar