O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

round — Round a floating-point value to the nearest integer

Usage

Float.round(num)

num : Floating point

Description

Returns the closest integer to num. Returns num itself if it’s an integer. Values ending in .5 are defined to be closest to the integer above.

Returns invalid if num can’t be converted to floating point or if the result doesn’t fit into an integer.

Examples

Float.round(17.0)

returns integer 17

Float.round(17.4)

returns integer 17

Float.round(17.5)

returns integer 18

Float.round(-17.0)

returns integer -17

Float.round(-17.4)

returns integer -17

Float.round(-17.5)

returns integer -17 (not -18)

Float.round(5e10)

returns invalid

Float.round(-5e10)

returns invalid

Float.round("foo")

returns invalid

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required