Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Letter 'e; in assigning value to float

 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
float a = 1.1e1f;
In this line variable a is assigned value 11.0. Can anybody please explain me how? Thanks
 
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
The notation

N.NEM

is called "scientific" or "exponential" notation. The E is a separator. The numbers to the left of the E are called the "mantissa", and the numbers to th e right are the "exponent". The value of the whole expression is the product of the mantissa times ten raised to the power of the exponent. Since 10 to the first power is ten, and 1.1 times ten is eleven, the value of the expression is 11.0 .

Obviously there's no reason why you'd ever write eleven in this format -- but it sure is convenient if you need to write 123 trillion!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the 'e' refers to 'exponent'

"1.1e1f" means

'take 1.1 and multiply it by 10^1"

"1.827e9f" means

take 1.827 and multiply it by 10^9, giving 1,827,000,000
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Ernest Friedman-Hill and Fred Rosenberger. I was not able to find this explanation anywhere and it helped me a lot. Thanks a bunch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic