Isaac Reefman
Isaac Reefman

Reputation: 597

Miscalculating sum(table.field) in form txtbox

I have a table tblTimeInLieu with a field HoursTaken containing these values: 1; 0.5; 2.25; 0.66

I then have a form frmTimeInLieu, Record Source: TimeInLieu, which contains a text box txtHoursUsed, Control Source: Sum([HoursTaken]) which returns this value: 4.41000003.

...

HOW!?

I've band-aided it by replacing the control source with FormatNumber(Sum([HoursTaken]), 2) so that it looks right for now, but I can't for the life of me work out what's going on.


Potential relevant information:

Upvotes: 0

Views: 27

Answers (1)

Erik A
Erik A

Reputation: 32632

Floating point number inaccuracy!

Since your column is a Single, which is the smallest floating number data type Access has, most operations that involves this column multiple times are bound to produce inaccurate results.

Either change your column type to Decimal, Currency, or use a rounding function to discard rounding data.

If you would change your column to a Double, the result would still be inaccurate, but with a smaller error.

Upvotes: 1

Related Questions