File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float values

 
Nila dhan
Ranch Hand
Posts: 161
  • 0
  • 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
Pie
Posts: 42966
73
  • 0
  • 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
  • 0
  • 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.,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic