• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

long with l , float with f, double with d

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When we declare a long variable

long l1 = 100l -> this l after 100 (Pl note this is NOT thousand this 100 and an l)
why we need to type l after the actual value since we already declared it's a long type ? Similaraly for double and float.

thanks very much for the reply.

- Susan
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) All three integer literals (decimal, hexadecimal, octal) are defined as int by default, but you can specify a long integer by putting an 'L' or 'l' after the number.

2) The int value range is -(2^31) to (2^31)-1 [-2,147,483,648 to 2,147,483,647]. you do not need "L" or "l" if the value in the int value
range.

3) A series of digits with a decimal point is of type double. Float numbers have the f or F suffix. Double numbers have d or D. If no suffix is provided, the default double type is assumed.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default, int literals are 32 bits.

100 is 32 bit of size. When you put l or L (lowercase L or uppercase), then it will be 64 bit long.

Similary floating point no. say 32.4 is by default 64 bit double literal.

32.4--->>> 64 bit double literal

32.4d or 32.4D ---->>> 64 bit size

32.4f or 32.4F ---->>> 32 bit size


Regards


Naseem Khan
[ June 17, 2006: Message edited by: Naseem Khan ]
 
susan waters
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks very much for the replys.
But I have a question here.

As you all said 32.4 by default 64 bit. What is the advantage of converting to 32 bit like 32.4F or 32.4f

similaraly integer,
you all said , for example 39 is integer literal of 32 bit size. When I say 39l or 39L it will be 64 bit. What advantage I get when I convert it to 64 bit by placing L or l as a sufix.

thanks very much for reply.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


As you all said 32.4 by default 64 bit. What is the advantage of converting to 32 bit like 32.4F or 32.4f



For long its fine

long l=45; Is correct. 32 bit size can be asssigned to long which is 64 bit of size.

but take this case..

float f=45.8; // will this compile. Surely not. 64 bit can't be assigned to 32 bit type.


So what will you do? You have to put suffix f or F here.

float f=45.8f or 45.8F;


Regards


Naseem
[ June 18, 2006: Message edited by: Naseem Khan ]
 
susan waters
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Naseem for your nice explonation. I clearly understand the concept. Thanks
Susan
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is adding a L or l to specify long is mandatory.. or it is optional....
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
long v1 = 10 \\ L or l optional for primitive assignment
Long v2 = 10L \\ mandatory for autoboxing
Long v3 = new Long(10) \\ Optional
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic