views:

45

answers:

2

I have a weird problem in asp.NET when calculating how many hours we need to invoice.

In the below example, we have a total of 75,9 hours that need to be invoiced. These hours are spread over several database rows (TimeIDs).

Basically, I always deduct the "amount_invoiced" from the "to invoice" hourly count:

TimeID:25433 - to invoice=75,9 - amount_invoiced=1
TimeID:25774 - to invoice=74,9 - amount_invoiced=1
TimeID:24688 - to invoice=73,9 - amount_invoiced=1,5
TimeID:24646 - to invoice=72,4 - amount_invoiced=2
TimeID:24890 - to invoice=70,4 - amount_invoiced=2
TimeID:25773 - to invoice=68,4 - amount_invoiced=2,25
TimeID:24455 - to invoice=66,15 - amount_invoiced=2,5
TimeID:25431 - to invoice=63,65 - amount_invoiced=2,5
TimeID:24552 - to invoice=61,15 - amount_invoiced=3
TimeID:24644 - to invoice=58,15 - amount_invoiced=3
TimeID:24727 - to invoice=55,15 - amount_invoiced=3
TimeID:25000 - to invoice=52,15 - amount_invoiced=4
TimeID:25195 - to invoice=48,15 - amount_invoiced=4,15
TimeID:24510 - to invoice=44 - amount_invoiced=4,5
TimeID:24419 - to invoice=39,5 - amount_invoiced=5
TimeID:25126 - to invoice=34,5 - amount_invoiced=5,5
TimeID:25064 - to invoice=29 - amount_invoiced=6,5
TimeID:24420 - to invoice=22,5 - amount_invoiced=7
TimeID:25251 - to invoice=15,5 - amount_invoiced=7,5
TimeID:24897 - to invoice=8,00000000000001 - amount_invoiced=8

Everything works ok, except for TimeID 24897. Somehow the calculation of 15,5 - 7,5 = 8,00000000000001

I'm baffled as to why this would happen. Has anyone experienced a similar issue?

+1  A: 

Sounds like you're using the wrong data type to store your values...you should be using decimal for accurate math results.

Justin Niessner
+1  A: 

Usual double internal storage problem. Been answered many, many times on this site (I've answered it more than once myself, and Mr Skeet has probably lost count). Example:

http://stackoverflow.com/questions/1398753

David M
Thanks for the info, problem is solved now.
Stijn Van Loo