• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float question

 
ty lee
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear helper:
double d=12.5
float f=12.5

is syntax f=12.5 correct?

what is different between f=12.5 and d=12.5?
 
vivekkumar sharma
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ty lee:
Dear helper:
double d=12.5
float f=12.5

is syntax f=12.5 correct?

what is different between f=12.5 and d=12.5?

the floating point constants(Literals) in java are treated as doubles
so float f = 12.5 will give compile time error
u need to declare and intialise it as
float f=12.5f;
to specificaly tell compiler u want f to be intialised as a float.
hope this helps
 
ty lee
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear vivekkumar sharma ,thank for helping
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic