You can use the built-in round()
function in Python to round a number to the nearest integer.
main.py66 chars4 lines
The round()
function can also be used to round a number to a specified number of decimal places.
main.py76 chars4 lines
Alternatively, you can use the math
module and its floor()
or ceil()
functions to round down or up to the nearest integer, respectively.
main.py135 chars9 lines
Note that both floor()
and ceil()
functions return a float
value. You can convert the result to an integer using the built-in int()
function if needed.
gistlibby LogSnag