C
Chris Dunaway
I am writing a simple point of sale type application. One of the
functions includes reading a weight from a scale and then multiplying
that weight by a UnitPrice to get an amount.
The scale returns its weight in pounds to 3 decimal places. We then
take this weight and multiply by the unit price per pound which is
$3.20.
Sometimes, I get total amounts that have more than 2 decimal places.
For example, if the scale reads .995 lbs and I multiply by the unit
price os $3.20, the result is $3.184.
When a transaction is entered into the transactions table, using a
money column, the value is stored unrounded (i. e. as 3.184).
I use the Decimal data type in C# so this works out fine.... sort of.
Inevitably on printed reports, sometimes the sums of the values are off
by a penny or two. This seems to be due to a rounding of the actual
values to 2 decimal places.
I am looking for a way to handle smoothly so that calcuations and
reports agree.
Does anyone have any algorithms or advice on a simple way to handle
this type of situation?
Thanks,
Chris
functions includes reading a weight from a scale and then multiplying
that weight by a UnitPrice to get an amount.
The scale returns its weight in pounds to 3 decimal places. We then
take this weight and multiply by the unit price per pound which is
$3.20.
Sometimes, I get total amounts that have more than 2 decimal places.
For example, if the scale reads .995 lbs and I multiply by the unit
price os $3.20, the result is $3.184.
When a transaction is entered into the transactions table, using a
money column, the value is stored unrounded (i. e. as 3.184).
I use the Decimal data type in C# so this works out fine.... sort of.
Inevitably on printed reports, sometimes the sums of the values are off
by a penny or two. This seems to be due to a rounding of the actual
values to 2 decimal places.
I am looking for a way to handle smoothly so that calcuations and
reports agree.
Does anyone have any algorithms or advice on a simple way to handle
this type of situation?
Thanks,
Chris