comparing floating point values for equality in c#

  • From: "Chris Westbrook" <westbc@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 2 Jan 2008 19:18:39 -0500

I'm trying to compare a calculated currency total to a total in the database 
stored as a float.  I'm having trouble with values that seem equal but in fact 
are not equal due to approximation.  I thought I could do something like if 
(Math.abs(value1-value2)>0.01D) //the numbers are not equal but that doesn't 
seem to work either.  How do you successfully compare currency values for 
equality?

Other related posts: