I'm trying to implement printf
and I want to know how printf
rounds floating-point numbers because I cannot find a general rule
If for example input => printf("|%.f| |%.1f| |%.2f| |%.5f| |%.12f", 0.000099, 0.000099, 0.000099, 0.000099, 0.000099);
Here is the output => |0| |0.0| |0.00| |0.00010| |0.000099000000
I use the method from IEEE-754 so our floating-point number in memory is: 0.000098999999999999994037755413067714016506215557456016540527343750
My question is when and how should I round my floating-point number?
I am looking for a general rule that I must follow for all floating-point numbers.