Python Forum
Add parameter to math.floor() to round to specific decimal point
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add parameter to math.floor() to round to specific decimal point
#1
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)
Reply
#2
why not: https://docs.python.org/3/library/functions.html#round
Reply
#3
There is round().
The word 'floor' has a meaning and part of it is "not beyond the decimal point".
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 1,198 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,643 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  Floor approximation problem in algorithm gradlon93 3 901 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  math.log versus math.log10 stevendaprano 10 2,301 May-23-2022, 08:59 PM
Last Post: jefsummers
  Floor division problem with plotting x-axis tick labels Mark17 5 2,047 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,704 Feb-24-2021, 05:09 PM
Last Post: bowlofred
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 2,990 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Floor division return value Chirumer 8 3,695 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE
  Printing digits after the decimal point one by one uberman321 1 1,702 Oct-20-2020, 08:10 AM
Last Post: bowlofred
  connecting the first point to the last point Matplotlib omar_mohsen 0 4,524 Jan-15-2020, 01:23 PM
Last Post: omar_mohsen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020