• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

dodgy float

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at times, I find
float f = 3.14
is false because it's a double.
Fine

then I read:
System.out.println("5.0==5L"+(5.0==5L));
is true because we can compare a float to an integer.

so I'm loosing it as to what a float is really [ apart from the obvious that it's 32 bits and must always have the f or F suffix]

and wat's the 'L' in 5L....long..?
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Netty,

System.out.println("5.0==5L"+(5.0==5L));


Here long 5 is getting **promoted** to double implicitly.

L or l is long. We have to use it because by default 5 is int and not long. So if you need a variable that must store long value it must be declared as

long s = 5L;

Ankur
 
Let's get him boys! We'll make him read this tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic