This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double

 
Sridhar Srinivasan
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
The double data type can accept an int rite?
double d=0x10
Why the following gives a run time exception?Can anybody pl explain?Thanks.
Double d1 = new Double("0x10");
[ May 22, 2004: Message edited by: Barry Gaunt ]
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The constructor that accepts string for wrapper classes is more restrictive from the one that accepts primitives. That is why you can't pass a hex string value.

Take this for an example:

Double d1 = new Double("010");
d1.doubleValue(); // print the result

is treated as an integer number of base 10, the leading zero (which represents that the number is octal) is simply ignored. So the value stored in 'd1' is 10, and not 12 as you might expect.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For this kind of question it's a good idea to look at the Java 1.4.2 API. It's a much better source of information than one's own intuition.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic