round()

Deprecated in 5.0.

Please use Math::Round instead.

round(x, precision): float

Round floating point value to the nearest integral value or floating point value with given precision.

Table 1. Parameters

x

Float

Floating point value.

precision

Integer

Optional number of decimal places to be left. If omitted or set to 0, x will be rounded to integral value.

Return

The integral value that is closest to x if precision is omitted or set to 0, or floating point value rounded to have given number of decimal places.

println(round(2.3)); // Will print "2"
println(round(3.8)); // Will print "4"
println(round(-2.3)); // Will print "-2"
println(round(-3.8)); // Will print "-4"
println(round(2.378, 2)); // Will print "2.38"
println(round(2.378, 1)); // Will print "2.4"