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

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

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