Python Forum
Add parameter to math.floor() to round to specific decimal point - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Add parameter to math.floor() to round to specific decimal point (/thread-8840.html)



Add parameter to math.floor() to round to specific decimal point - gabrield - Mar-09-2018

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)



RE: Add parameter to math.floor() to round to specific decimal point - Larz60+ - Mar-09-2018

why not: https://docs.python.org/3/library/functions.html#round


RE: Add parameter to math.floor() to round to specific decimal point - wavic - Mar-09-2018

There is round().
The word 'floor' has a meaning and part of it is "not beyond the decimal point".