This is the documentation for the development version. There are no official binaries for it; build it from the source code in git. Download links on these pages work only after the release. For the current release, see version 7.0.

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.0"
println(round(3.8)); // Will print "4.0"
println(round(-2.3)); // Will print "-2.0"
println(round(-3.8)); // Will print "-4.0"
println(round(2.378, 2)); // Will print "2.38"
println(round(2.378, 1)); // Will print "2.4"