This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

max int in float???

 
pioneer
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Conversion
{
public static void main(String[] args)
{
int i = 1234567890;
float f = i;
System.out.println(i - (int)f);
}
}
This does not print 0. What is the range of int that can be correctly converted to float without loss of precision? I made i=99999999 and it printed -1 but when i made i=100000000 it printed 0.
 
pioneer
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this old thread.
Hope that helps,
Corey
 
pioneer
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunitha,
The problem here is not with range. But it is with precessions.
When you save a big number in float it converts it in to Exp format like 1.23456794E9 and rounds the last digits if they wouldn't fit it in to float. when you get save it back to int it just converts the exponential format back to int.
For exam I don't think we need to understand the precessions as they are system dependent. If you use strictfp then the precessions will be same across all platforms.
Did this help you???
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!