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
• Devaka Cooray
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Jeanne Boyarsky
• Tim Cooke
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Tim Moores
• Mikalai Zaikin
• Carey Brown
Bartenders:

# Doubt with Float class

Ranch Hand
Posts: 274
• Number of slices to send:
Optional 'thank-you' note:
What is the output
{
Float f1 = new Float("4.4e99f");
Float f2 = new Float("-4.4e99f");
Double d1 = new Double("4.4e99");
System.out.println(f1);
System.out.println(f2);
System.out.println(d1);
}
a) Runtime error
b) Infinity
-Infinity
4.4E99 ///why?
c) Infinity
-Infinity
Infinity
d) 4.4E99
-4.4E99
4.4E99

Doubt: how is it working for Double and not Float?

pls help
regards,
gitesh

Ranch Hand
Posts: 99
• Number of slices to send:
Optional 'thank-you' note:
This is because of the range of float. The largest positive finite float literal is 3.4028235e38f. The smallest positive finite nonzero literal of type float is 1.40e-45f.

You will get a compiler error if you use a float literal out of the specified range like the following code

For more details have a look here

Java Cowboy
Posts: 16084
88
• Number of slices to send:
Optional 'thank-you' note:
It does not work as you expect for Float because the maximum value that you can store in a Float is approximately 3.4e38, and 4.4e99 is larger than that.

The range for Double is larger (the max. is approx. 1.8e308).

Ranch Hand
Posts: 49
• Number of slices to send:
Optional 'thank-you' note:
I did not think we are required to know the range of values each primitive type and their respective wrapper class can hold for the exam. Did this change?
[ August 28, 2007: Message edited by: Chris Stann ]

Ranch Hand
Posts: 35
• Number of slices to send:
Optional 'thank-you' note:
This is because of the range of float. The largest positive finite float literal is 3.4028235e38f. The smallest positive finite nonzero literal of type float is 1.40e-45f.

Gitesh Ramchandani
Ranch Hand
Posts: 274
• Number of slices to send:
Optional 'thank-you' note:
Source:

Amit Poddar-Q29

Gitesh Ramchandani
Ranch Hand
Posts: 274
• Number of slices to send:
Optional 'thank-you' note:
thanks for help

 CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad: a bit of art, as a gift, that will fit in a stocking https://gardener-gift.com