31
Mar

double a=4.35;

System.out.println(100*a);

answer is 434.99999999999994

Why is not be 435.00 ?


Answer:
This is a FAQ on Programming & Design…

to make the computer go faster, double and floats are calculated as a binary number with an exponent. Use BigDecimal number type to regain your familiar base-10 arithmatic. If you software program deals with money, use integer math for the dollars and interger math for the cents.

I consider float and double as math numbers for measurements, not for units.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

This entry was posted on Monday, March 31st, 2008 at 4:42 am and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or TrackBack URI from your own site.

Leave a reply

Name (*)
Mail (*)
URI
Comment