Bottom Page

• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Add parameter to math.floor() to round to specific decimal point gabrield Unladen Swallow Posts: 1 Threads: 1 Joined: Mar 2018 Reputation: 0 Likes received: 0 #1 Mar-09-2018, 07:20 PM 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) ``` Larz60+ aetate et sapientia Posts: 7,668 Threads: 289 Joined: Sep 2016 Reputation: 286 Likes received: 1059 #2 Mar-09-2018, 07:40 PM why not: https://docs.python.org/3/library/functions.html#round wavic So-and-so of the Yard Posts: 2,870 Threads: 37 Joined: Sep 2016 Reputation: 89 Likes received: 358 #3 Mar-09-2018, 08:43 PM 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 « Next Oldest | Next Newest »

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)