We have round(), ceil(), floor(), they all round float to int. Do we have functions to round float with 5 or more decimal to its second or third decimal?
Otherwise, multiply by 100 or 1000, round and then divide again. But this might not work because it's not always possible to store decimal numbers exactly as a binary number.
Answers
For printing? Use nf()
Otherwise, multiply by 100 or 1000, round and then divide again. But this might not work because it's not always possible to store decimal numbers exactly as a binary number.
What about modulo?
@koogs thanks for pointing to nf() and multiply and divide is good enough too. @benja thanks for this interesting and short solution.