clockblocks.utilities.snap_float_to_nice_decimal
- clockblocks.utilities.snap_float_to_nice_decimal(x: float, order_of_magnitude_difference=7) float [source]
If x is near to a nice decimal, this rounds it. E.g., given a number like 8.01399999999999214, we want to round it to 8.014. We do this by comparing what we get if we round coarsely to what we get if we round precisely, where order_of_magnitude_difference represents how much more precise the precise round is than the course round. If they’re the same, then we should be rounding.
- Parameters:
x – number to snap
order_of_magnitude_difference – how many orders of magnitude we compare rounding across
- Returns:
the rounded value