Java Reference
In-Depth Information
printf("parseInt('%s') = %d", "-1969", parseInt('-1969'));
printf("parseInt('%s') = %s", "- 1969", parseInt('- 1969'));
printf("parseInt('%s') = %s", "xyz", parseInt('xyz'));
parseInt('1969') = 1969
parseInt(' 1969') = 1969
parseInt(' 1969 Hello') = 1969
parseInt('Hello1969') = NaN
parseInt('0x1969') = 6505
parseInt('0x1969', 16) = 6505
parseInt('1001001', 2) = 73
parseInt('-1969') = -1969
parseInt('- 1969') = NaN
parseInt('xyz') = NaN
The parseFloat() Function
The
parseFloat()
function is used parse a floating-point number from a string. It has the
following signature:
parseFloat(string)
The
parseFloat()
function works the same way as the
parseInt()
function, except
that the former parses
string
for a floating-point number. It returns
NaN
if
string
does
not contain a number. The following code show the output of calling the
parseFloat()
function with different arguments:
printf("parseFloat('%s') = %f", "1969.0919", parseFloat('1969.0919'));
printf("parseFloat('%s') = %f", " 1969.0919", parseFloat(' 1969.0919'));
printf("parseFloat('%s') = %f", "-1969.0919", parseFloat('-1969.0919'));
printf("parseFloat('%s') = %f", "-1.9690919e3", parseFloat('1.9690919e3'));
printf("parseFloat('%s') = %f", "1969Hello", parseFloat('1969Hello'));
printf("parseFloat('%s') = %f", "Hello", parseFloat('Hello'));
parseFloat('1969.0919') = 1969.091900
parseFloat(' 1969.0919') = 1969.091900
parseFloat('-1969.0919') = -1969.091900
parseFloat('-1.9690919e3') = 1969.091900
parseFloat('1969Hello') = 1969.000000
parseFloat('Hello') = NaN
Search WWH ::
Custom Search