This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Doubt int he output of this code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Doubt int he output of this code" Watch "Doubt int he output of this code" New topic
Author

Doubt int he output of this code

abin joy
Ranch Hand

Joined: Jul 29, 2008
Posts: 35
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

Joined: Sep 04, 2008
Posts: 10
I cann't follow you!


Do everything by yourself!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

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.


[Jess in Action][AskingGoodQuestions]
abin joy
Ranch Hand

Joined: Jul 29, 2008
Posts: 35
doubt cleared
thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt int he output of this code
 
Similar Threads
Float.valueOf() method and NumberFormatException
float
Invoking equals method on float object
Assignment doubt
Wrapper