View Single Post
  #13 (permalink)  
Old 10-14-2008, 10:25 AM
fishtoprecords's Avatar
fishtoprecords fishtoprecords is offline
Senior Member
 
Join Date: Jun 2008
Posts: 522
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Eranga View Post
fishtoprecords, I'm totally confusing with your comments. You advice not to use double because of decimal points? Is it?
Yes, you are confused.
My advice is to never use double or float for currency.

Floating point numbers are great for engineering. Engineers design for limited accuracy in numbers. Floating point numbers are rarely exact (they are only exact for powers of two, such as 1/2, 1/4, etc.)

Accountants insist on exact numbers. Any system that uses money must exactly add up. You simply can not do this with float or double.

The solution is to use fixed point. The easiest is to use the integer number of pennies, and accept the decimal point on input, and put it there on output.
Reply With Quote