aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes conversion Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "conversion Doubt" Watch "conversion Doubt" New topic
Author

conversion Doubt

agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
public class Conversion
{
public static void main(String[] args)
{
int i = 1234567890;
float f = i;
System.out.println(i - (int)f);
}
}

The Above Code will Not Print 0.
Why?
#################################
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
Agrah,

This has to do with the complex way floats store decimal numbers. Both ints and floats use 32-bits to represent numbers, but the precision on floats varies depending on the kind of significant digits it has to store. Floats tend to be slightly inaccurate as a result and you should not use them to represent values that need accuracy (like money).
Thitipong Suparurkrat
Greenhorn

Joined: Sep 20, 2005
Posts: 6


try this
agrah upadhyay
Ranch Hand

Joined: Sep 01, 2005
Posts: 579
Then How To Solve This Type Of Problem.Plz Also tel Me More Clearly About Significant Digits in Decimal As Well As Binary Number Context

Thanx A Lot
####################################3
Agrah Upadhyay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: conversion Doubt