How do you round UP a number?
In Python, you can use the ceil()
function from the math
module to round a number up. Here is an example:
import math
x = 3.14
rounded_x = math.ceil(x)
print(rounded_x)
This will output 4
, because 3.14
rounds up to 4
.
Another way is to use the round()
function. round()
function round a number to the nearest integer, if the decimal part of the number is >= 0.5, then it rounds up, otherwise it rounds down.
x = 3.14
rounded_x = round(x)
print(rounded_x)
This will also output 4
, because 3.14
is rounded up to 4
.