roundoff in python code example
Example 1: how to round in python
round(21.57)
round(5.473, 2)
Example 2: python round down
>>>import math
>>> math.floor(1.6)
1
>>> math.floor(2)
2
>>> math.floor(3.9)
3
Example 3: round off float to 2 decimal places in python
answer = str(round(answer, 2))
Example 4: how to round to two places python
round(number, decimal places)
Example 5: how to round a decimal to the nearest whole number in python
>>> import math
>>> math.ceil(1.2)
2
>>> math.ceil(2)
2
>>> math.ceil(-0.5)
0
Example 6: how to round a number up in python
>>> import math
>>> math.ceil(3.2)
4