Bottom Page

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)
Quote
#2
why not: https://docs.python.org/3/library/functions.html#round
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Floor Division cf. math.floor() Devarishi 3 208 May-22-2019, 06:35 AM
Last Post: heiner55
  testing for Decimal w/o importing decimal every time Skaperen 7 586 May-06-2019, 10:23 PM
Last Post: Skaperen
  Cant get my head round the algorithm hshivaraj 1 204 Apr-09-2019, 10:38 PM
Last Post: Yoriz
  decimal point or comma Skaperen 8 581 Mar-17-2019, 06:02 AM
Last Post: DeaD_EyE
  mixed decimal point characters Skaperen 1 284 Mar-10-2019, 05:23 PM
Last Post: stullis
  Unexpected round behavior pythonCoder 1 304 Feb-19-2019, 02:39 PM
Last Post: marienbad
  Logic of using floor division and modulus for a different variable at different time SB_J 2 402 Nov-01-2018, 07:25 PM
Last Post: SB_J
  Is // operator is the same as math.floor() quazirfan 7 1,476 Mar-19-2018, 01:51 AM
Last Post: casevh
  Round a number up to certain significant figures brocq_18 4 2,331 Apr-06-2017, 06:49 PM
Last Post: alicarlos13

Forum Jump:


Users browsing this thread: 1 Guest(s)