I have this code in C#
double result = 480 - 460.8;
Why result is 19.199999999999989 instead of 19.2?
you should format your double precision of the result output:
double result = 480 - 460.8;
String.Format("{0:0.##}", result);
test example:
https://ideone.com/27OfP4
update:
there is another way without string formatting you can use method Math.Round with two digits after decimal place :
Math.Round(result,2);
example:
https://ideone.com/2Q6RPD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With