• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Float constructor parameter

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Float f1 = new Float("1e1f"); //Line 1
Float f2 = new Float(".1e1d"); //Line 2



What are "1e1f" and ".1e1d"?
Why does this code compile just fine and return 1.0 1.0 if we print f1 and f2 printed?
Please help, I feel weak in this area!
Possibility of NumberFormatException in such questions makes me feel confused.


Source of question:
The question is excerpt from one of the Danchisholms question collection of Wrapper classes.



Regards,
cmbhatt
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find the grammar that describes a floating point number in the Java Language Specification Section 3.10.2

f1 will actually print 10.0

e is an exponent indicator

f indicates the type of floating point number

So 1e1f means a variable of type float which is equal to 1 x 10^1 = 10.0f.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,
f1 prints 10.0

Oh, it is exponent factor!!!

Do I really need to refer to the link you have given? or given detail
by you alright for test.

Anyways!

Thanks Keith,
cmbhatt
[ April 19, 2007: Message edited by: Chandra Bhatt ]
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry,
f1 prints 10.


keith is right.f1 will print 10.0.even if you remove exponential part.

Thanks
raj
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic