math.round
Defined in module
"math"from "math" import roundRounds x to the nearest integer
Parameters
x | number | the number to round |
Return value
The nearest integer value to x, as a float.
Notes
A halfway value rounds away from zero, not to the nearest even integer: round(2.5) is 3 and round(-2.5) is -3.
Example
from "math" import round
println("round(2.4) =", round(2.4))
println("round(2.6) =", round(2.6))
// a halfway value rounds away from zero, not to the nearest even integer
println("round(2.5) =", round(2.5))
println("round(-2.5) =", round(-2.5))
println("type(round(2.5)) =", type(round(2.5)))Output:
round(2.4) = 2
round(2.6) = 3
round(2.5) = 3
round(-2.5) = -3
type(round(2.5)) = floatSee also
floor | Rounds x downward to the nearest integer |
ceil | Rounds x upward to the nearest integer |
abs | Returns the absolute value of x |
| math | module index |