Double dissapear on canvas
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?
Comment
Answer by Positive7 · Aug 21, 2017 at 02:01 PM
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 ...
Answer by saharolds · Apr 20, 2018 at 08:23 AM
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.)
Your answer
![](https://koobas.hobune.stream/wayback/20220612133216im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Calculate arithmetic problem from text 1 Answer
Relative Position Not Constant? 0 Answers
Unity problems with bigger number than 10^39 2 Answers