jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on float variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on float variables" Watch "Question on float variables" New topic
Author

Question on float variables

Nina Binde
Ranch Hand

Joined: Sep 24, 2004
Posts: 85

This compiles fine and f4.intValue() gives 10 as result, f5.floatValue() gives 1.0 as result. I fail to understand how the result is calculated. Is including e,f and d anywhere in the literal valid?

Thanks for the answers!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
"1e1f" that's a float literal because of the "f" at the end.
"1e1" that's the exponential notation and means 1 times (ten to the power of 1). Ten to the power of 1 is ten. So "1e1f" is 10.0. The integer part of 10.0 is 10.

I leave you to work out the other one.
[ October 24, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
rogel garcia
Ranch Hand

Joined: Dec 19, 2003
Posts: 41
This works like this

1e1 means 1 x 10 powered 1 == 10
this is a double number, since every floating point literal is a double

You can put the D or F to explicity declare this number as a float or double

The results were different because
.1 == 0.1
1 == 1.0


SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on float variables
 
Similar Threads
Doubt in math.round
problem with constructors of Long and Float
Wrapper class question from Danchisolm
Math.round() method
Float.valueOf() method and NumberFormatException