• 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

SCJP doubt

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
float f = 0.9f;
double d = 0.9;
System.out.println(f == d);
Most of us would think that the output of this code snippet is true but the fact is it will return false due to numeric promotion. If you compare a float value with a double value, the float value will be promoted to double, for this case when f is promoted to double, it will produce 0.8999999761581421. And if you compare this value to 0.9, obviously it will return false.
My question is are there these types of question in the SCJP exam which I think is sort of confusing? Cause at first glance, IMO, most people will think the answer would be true well in fact, it return false.

Thanks...
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yikes.......somethings' messy ....

float f1 = 0.9f;
double d1 = 0.9;

System.out.println ( f1==d1 );
System.out.println ( "f1 = " + f1 );
System.out.println ( "d1 = " + d1 );
Output is:
false
f1 = 0.9
d1 = 0.9
I am on a DELL PC running on Windows98 (if it matters)
with a JDK 1.2.2.
Not sure whats going on
I appreciate you getting such a doubt though
Regds.
- satya

[This message has been edited by satya5 (edited April 19, 2000).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic