I'm having problems with my game with fluctuating values and can not round the decimal values. I tried even this function:
const double dbShift = pow (10.0, 5);
return floor (pValor * dbShift + 0.5) / dbShift;
This function can run "floor (pValor * dbShift + 0.5)" correctly. However the divide by dbShift again, happens again the same problem.
In my game, for example, I have a double to save the tempoDecorrido in milliseconds (5337, for example). When trying to convert in seconds (5337 / 1000.0f), the return value always brings an unnecessary amount of decimal places (5.3369999999999997 instead of 5337).
This causes major problems multiply when floating by other values such as position and rotation vectors.
I searched on google and there are several sites that explain the cause of the problem, but none that have the solution thereof, unless u want to display the value on the screen as a string, but this is not the case. I need to work with floating values, not with information on the screen.
Finally, someone in a definitive solution to this. Force floating values to have five decimal places, for example?
Recalling that already test the above function without success. Already, I appreciate the help.