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

Get Learning WML, and WMLScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.