Parsing double with suffix

A

Andrea Desole

I would generally expect the string "5" to be parses into the double
5.0, and the string "5f" not to be parsed. However I noticed, with big
surprise, that the string "5f" is also parsed into the double 5.0. So is
the string "5d".
I assume that the method parseDouble sees d and f as suffixes for the
type float and double. In fact, all the other letters after the number
5, including l, seem to fail.
This looks pretty strange to me, and I would like to find a way get an
error when parsing "5f" or "5d". Any help appreciated.
Thanks
 
J

Juergen Nickelsen

Andrea Desole said:
I assume that the method parseDouble sees d and f as suffixes for
the type float and double. In fact, all the other letters after the
number 5, including l, seem to fail.

This is as documented in Double.parseDouble()/valueOf() and section
3.10.2 of the language specification.
 
A

Andrea Desole

Juergen said:
This is as documented in Double.parseDouble()/valueOf() and section
3.10.2 of the language specification.
Damn, why don't I read the documentation of methods referred to by other
methods' documentation.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top