How to round double to 2 places after comma. I have a problem that my value dissapears from screen.
Is there something like maths.round for double?
const double Num = 0.123456;
var num0 = Num.ToString(“0.00”); //0.0, 0.00, 0.000 …
var num1 = Num.ToString(“n2”); //n1, n2, n3 …
This will accurately round to two decimal places:
double num = 23.4567;
double roundedNum = (int)(num * 100 + 0.5) / (double)100;
(roundedNum equals 23.46)
(Setting a number as an int will truncate everything after the decimal. If you add 0.5 to a number and then set it as an int it is the same as rounding to the nearest int.)