HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 21 February 97

Foil 24 The parseInt parseFloat System functions

From Feb 17/19 Delivered Lecture for Course CPS616 -- aJavaScript Language Objects and Frames CPS616 spring 1997 -- Feb 17 and 19 1997. by Geoffrey Fox * Important Information in IMAGE
Secs 136.8
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 Fri Feb 21 1997