Hi,
How can I round a float number like 0.00877193 to 0.01?
Thanks,
Carlos.
Hi,
How can I round a float number like 0.00877193 to 0.01?
Thanks,
Carlos.
1. multiply by 10 until you have a result > 0,and remember how many iterations you needed (power of10)
2. multiply your input number by 10 in the power of iterations-1, and use ceil() on the result. (in this case it will give you 1.0)
3. divide back by 10 in the power of iterations-1.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Or, to use your example's case, add 0.005 and simply truncate at the second decimal place.
Bookmarks