Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt int he output of this code

 
abin joy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given

code
-------------------------
Float f2=new Float(3.14f);
System.out.println("byte="+f2.byteValue());
System.out.println("short="+f2.shortValue());
System.out.println("intt="+f2.intValue());
System.out.println("long "+f2.longValue());
}

code
----------------------------------
wat is the criteria for getting the value getting truncated to 3
All except

1)System.out.println("double "+f2.doubleValue());
2)System.out.println("float "+f2.floatValue());

truncates the value to 3
I expect f2.longValue also to behave differently rather than printing 3
 
Tony Fu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cann't follow you!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
byte, short, int, and long are all "integral types", meaning they can only represent integers -- numbers with no fractional parts. None of those types can hold 3.14, but they can hold 3. float and double are "floating point types", and they can represent numbers with fractional parts.
 
abin joy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doubt cleared
thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic