parseFloat() [FF, IE 3]

Converts a string to a floating-point number as long as the first character is a number. If the first character is not a number, parseFloat() returns NaN (not a number). If the string is a number followed by letters, parseFloat() grabs the first set of numbers in the string.

Example:

var the_string = "3.14etc";
var the_numbers = parseFloat(the_string);

The variable the_numbers contains 3.14.

Get The Book of JavaScript, 2nd Edition 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.