Win a copy of Design for the Mind this week in the Design 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic