[DLSLUG-Discuss] Java fluke, double precision pitfall

Bill McGonigle e-mail addresses are not shown in archives
Thu Dec 29 09:56:04 EST 2005

On Dec 29, 2005, at 04:00, Roger wrote:

> 1.2 minus 1.0 = 0.19999999999999996

You're seeing the floating point precision problem.  The IEEE specifies 
a standard for representing arbitrarily large floating point numbers in 
a 32-bit storage space.  Clearly, something has to give.

Here's a decent overview from Sun:


And a simple explanation from Microsoft:


Try your code using Integer types and you should get 0 == 0, but you 
have a fixed range of values for the variable.


Bill McGonigle, Owner           Work: 603.448.4440
BFC Computing, LLC              Home: 603.448.1668
[e-mail addresses are not shown in archives]           Cell: 603.252.2606
http://www.bfccomputing.com/    Page: 603.442.1833
Blog: http://blog.bfccomputing.com/
VCard: http://bfccomputing.com/vcard/bill.vcf

More information about the DLSLUG-Discuss mailing list