Re: [Slightly OT] Dealing with fractions of cents

Tech-Archive recommends: Fix windows errors by optimizing your registry



How about using Math.RoundOff


"Chris Dunaway" <dunawayc@xxxxxxxxx> wrote in message
news:1157550900.287805.30530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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



.



Relevant Pages

  • [Slightly OT] Dealing with fractions of cents
    ... 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. ... Inevitably on printed reports, sometimes the sums of the values are off ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Slightly OT] Dealing with fractions of cents
    ... What you're after is called Bankers Rounding. ... 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. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Slightly OT] Dealing with fractions of cents
    ... What I would suggest is that as soon as you assign a price to anything, ... 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. ...
    (microsoft.public.dotnet.languages.csharp)
  • [PATCH 20/30] sched: fix load scaling in group balancing
    ... doing the load balance will change cfs_rq->load.weight ... but since that's part of the scale factor, we'll scale back with a different ... amount. ... Weight getting smaller would result in an inflated moved_load which causes ...
    (Linux-Kernel)
  • Re: The take home message
    ... Exercise has a small but repeatedly found weightloss effect.Here is a free ... The amount of activity needed to prevent weight gain is unknown. ... than controls but were not different from each other. ...
    (alt.support.diabetes)