3 ms·
> I use to think like that, Like what? > When people are faced with "I have to have this number with 2 decimals", they sometimes write a = round(a * 100)/100;
by kazinator 11y ago
> I use to think like that,
Like what?
> When people are faced with "I have to have this number with 2 decimals", they sometimes write a = round(a * 100)/100; forgetting that 'a' is a float (or double), and then they completely forget that the new 'a' is just not accurate.
This is in fact perfectly accurate when decimal floating point is used. "float" and "double" aren't decmal, are they.
But I repeat myself.
For round() you could even have some decimal-based rounding like banker's.
> Issues with floats arise on simple operations such as addition.
Not when they are decimal, repeating myself again.