Name

parseFloat — Convert a string to a floating-point value

Usage

Lang.parseFloat(str)

str : String

Description

Attempts to parse the string str as a floating-point literal. A leading + or - may be included; any spaces at the start of the string are ignored, as are any characters at the end that can’t be parsed as part of the number.

Returns invalid if str can’t be parsed as a floating-point value, or if the interpreter doesn’t support floating-point operations.

Examples

Lang.parseFloat("123.456")

returns floating-point 123.456

Lang.parseFloat("17")

returns floating-point 17.0

Lang.parseFloat(" -7.2 C")

returns floating-point 7.2

Lang.parseFloat(" 55.3 mph")

returns floating-point 55.3

Lang.parseFloat("6e+3")

returns floating-point 6000.0

Lang.parseFloat(" .3")

returns floating-point 0.3

Lang.parseFloat("foo")

returns invalid

Lang.parseFloat(false)

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.