• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Double

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic