Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float values

 
Nila dhan
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,could anyone make me clear about this.
If i declare a variable like this, float a=1; it compiles without any error.But if i say float a=1.0 the following compliation error occurs "possible loss of precision" why is is?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because a value like "1.0" is considered to be a double. If you're certain that it's a float (and that's a safe assumption in this case), write it like "1.0f" or "1.0F". That indicates that it should be treated like a float.
 
muhsin sabeer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default data type for floating literal is double. So, when u declare float literal and assign double value should cause that error. E.g.,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic