0
how to prevent float from rounding off?
I want to display the float 2.378024 as 2.37. Anyone one know how to achieve this?
2 Antworten
0
You have to give a hint that you want to know it precisely.
If you write cout << 5/2;, you will get 2 as a result. If you write 5.0/2 or 5/2.0, then you get the decimal too.
It's a different datatype, like Roel said, so if you want to store a decimal, you can't write int x = 5.3;, but have to write double x = 5.3; (plus a few other options).
0
you could use double which stores decimal numbers more precise
edit. I accidently deleted my first post