HELP! * GREY=local LOCAL HTML version of Foils prepared 15 January 1997

Foil 36 The parseInt parseFloat System functions

From JavaScript Tutorial for CPS616 Technologies of the Information Age 1997 Basic Information Track of CPS -- Spring Semester 97. by Geoffrey C. Fox * Important Information in IMAGE

These are system functions ( not string methods) that convert strings to numbers
parseInt("15") or equivalently parseInt("15",10) both return the number 15
The optional second argument is radix so that parseInt("15",8) returns 17
If input string begins with "0x" the default radix is 16 (hexadecimal) whereas if it begins with "0" the radix is 8 (octal) -- otherwise default radix is 10
x = 1 +"1"; // evaluates to "11" whereas
x = 1 + parseInt("1"); // evaluates to 2
parseFloat(string) returns floating point equivalent of string
  • var x = "0.0314E+2"; var y = parseFloat(x); // sets y = 3.14
on platforms that support it, parseInt and parseFloat will return NaN (Not a Number) when argument is inappropriate



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Feb 19 1997