Python Forum

Full Version: Add parameter to math.floor() to round to specific decimal point
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It would be fantastic if there could be an easier way to round down to a specific decimal point using math.floor(). Then users wouldn't have to code a way around like this example below:
# Method to round numbers down, n being the number and d being the number of places after the decimal
def roundDown(n, d=8):
    if d > 0:
        d = int('1' + ('0' * d))
        return floor(n * d) / d
    elif d == 0:
        d = int('1' + ('0' * d))
        return round(floor(n * d) / d)
There is round().
The word 'floor' has a meaning and part of it is "not beyond the decimal point".