in reply to Numeric Comparisons Randomly Giving the Wrong Result

As others have already pointed out, you are running into floating-point errors. There are a number of solutions you might want to try:

If this is a financial application, then the use of integer values, if possible, should be the way to go.

  • Comment on Re: Numeric Comparisons Randomly Giving the Wrong Result

Replies are listed 'Best First'.
Re^2: Numeric Comparisons Randomly Giving the Wrong Result
by girarde (Hermit) on Sep 30, 2010 at 14:48 UTC
    That should be cents/farthings/bah

      Do they still have farthings? They're not worth a ... well, you know.

      As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re^2: Numeric Comparisons Randomly Giving the Wrong Result
by DrHyde (Prior) on Oct 05, 2010 at 09:51 UTC
    Using integer values, you're still stuffed. How do you calculate 17.5% of 100, using only integers?