Hi,
I'm having a problem rounding. See the following code:
The expected result would be 47.79, is correct in not making the rounding? I noticed that he only does when rounding the third decimal place is greater than 5.
Thanks,
Marcelo E. Geyer
Printable View
Hi,
I'm having a problem rounding. See the following code:
The expected result would be 47.79, is correct in not making the rounding? I noticed that he only does when rounding the third decimal place is greater than 5.
Thanks,
Marcelo E. Geyer
if you try 47.795, you will get 47.80.
if I'm not mistaken, then this is called banker's rounding.
I am not sure if/how that can be changed to mathematical rounding.
Actually, this is probably not a problem with Qt but with the underlying compiler float operations. 47.785 is probably being represented as 47.78499842... (for example) in the actual register, and so, is being round down to 47.78 since it is not greater than or equal to 47.785.
Here's a Wikipedia entry about floating point numbers that might help you: http://en.wikipedia.org/wiki/Floating_point
Hope that helps.
I'm seeing the class knumber api KDE _round the method of this class can help with correct rounding. Follow the link:
http://api.kde.org/4.x-api/kdeutils-...pp_source.html