0
Rounding
Idk how to round numbers in python, but I need both rounding up and down so I can complete a challenge. Does anyone know how?
2 Antworten
+ 5
Python has a built in function 'round'. Alternatively, you could use the math module depending on your use case.
https://www.geeksforgeeks.org/how-to-round-numbers-in-python/
https://code.sololearn.com/chkXZ0smaF3u/?ref=app
+ 3
Python has a built-in function called "round()". It takes 1 or 2 parameters: round(number,decimal)
Where:
- number: The number you want to round up
- decimal[OPTIONAL]: Round up to {decimal} decimal places. If the decimal is not set, the default is 0..(It rounds up to the last digit of that number, as default). Use negative values for getting the numbers before the decimal..
print(round(13.45678)) #13
print(round(13.45678,1)) #13.5
print(round(946,-1)) #950, since decimal 0 is the last digit.
print(round(956,-2)) #1000