You know when you're in science class, and asked to round to 2 sig figs, but your answer is
5.2501...? You should round to
5.3, but that's just so unsatisfying! By rounding to
5.3, you're off by a whole 0.05, which is a large amount compared to 0.1 (the place value you're rounding to)! So help me round in a satisfying way.
To round in a satisfying way, you must round at the first digit you come across that produces a relatively small error - less than half of the maximum error possible when rounding. Basically, you need to round whenever you encounter 0, 1, 8, or 9. If that never happens, return the input as is. Do not round on leading zeroes or ones - that just doesn't feel satisfying.
A string or float value that represents a nonnegative decimal number.
The same decimal number rounded satisfactorily, in either string or float format.
Input -> Output 0 -> 0 0.5 -> 0.5 0.19 -> 0 0.8 -> 1 5.64511 -> 5.645 18.913 -> 20 88.913 -> 100 36.38299 -> 36.4 621 -> 620 803.22 -> 1000 547.4726 -> 547.4726
This is a code-golf challenge, so shortest code wins!