Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 13 total
Thread Drop down calculator
Wed, Mar 18 2009 10:03 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate


I'm writing a drop down calculator component - I know there are a number of calculator components out there but a) I want it to share the look of my other homebrew components; b) I loath those with number buttons (in a touch screen app possibly but not in a normal program); c) its only going to do simple stuff + - * / % (). The parser is working happily and even giving the right answers. I'm going to have integer, float, money available and a thought struck me - for the money should I 1) do the calculation with unlimited decimal places and just format at the end or 2) round (in some way) after each calculation.

Any views?

Roy Lambert
Wed, Mar 18 2009 10:14 AMPermanent Link

"Rita"
Bankers rounding for lolly always .00000 but see
http://en.wikipedia.org/wiki/Rounding
A search on google throws up a lot of those that
have been there before.
Trust them bankers to squeeze the last drop or
smear of blood from peeps.
Rita BankersRounder.
"Roy Lambert" <roy.lambert@skynet.co.uk> wrote in message
news:1BDF0595-03D6-4C72-AD9D-9D28D192C009@news.elevatesoft.com...
>
> I'm writing a drop down calculator component - I know there are a number
> of calculator components out there but a) I want it to share the look of
> my other homebrew components; b) I loath those with number buttons (in a
> touch screen app possibly but not in a normal program); c) its only going
> to do simple stuff + - * / % (). The parser is working happily and even
> giving the right answers. I'm going to have integer, float, money
> available and a thought struck me - for the money should I 1) do the
> calculation with unlimited decimal places and just format at the end or 2)
> round (in some way) after each calculation.
>
> Any views?
>
> Roy Lambert

Wed, Mar 18 2009 11:05 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Rita


Most of the posts I've seen are talking about rounding a result, I'm wondering whereabouts in a process to apply rounding. My initial thoughts are at the end of the process but it can make a difference if you choose to round after each step of a calculation. eg

(22/7)*100

Round the end result and you get 314.29 but if you round at each stage you would end up with 314

Roy Lambert
Wed, Mar 18 2009 1:57 PMPermanent Link

"Malcolm"
Roy

I would round at any point where you have a formal result to be
displayed.
If you have to 'show your workings' then I think you have to round
each displayed result then use the rounded value for the next stage.

In the case of something like an itemised invoice, each line has to
be rounded and if you don't add up the rounded figures, the customers
will complain you got it wrong  Surprised

But I guess it does depend on the circumstances so that if interim
results are just for info they could be in their full glory <shrug>

Malcolm
Thu, Mar 19 2009 2:45 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Malcolm


Thanks - you've managed to write what was wandering lost inside my head - I can now figure out which way to go.

Roy Lambert
Sun, Mar 22 2009 5:51 PMPermanent Link

Sanford Aranoff
Malcolm wrote:
>
> Roy
>
> I would round at any point where you have a formal result to be
> displayed.
> If you have to 'show your workings' then I think you have to round
> each displayed result then use the rounded value for the next stage.
>
> In the case of something like an itemised invoice, each line has to
> be rounded and if you don't add up the rounded figures, the customers
> will complain you got it wrong  Surprised
>
> But I guess it does depend on the circumstances so that if interim
> results are just for info they could be in their full glory <shrug>
>
> Malcolm

Round the final result. Don't forget that if the last digit
is 5 you round to even.
4.5 is about 4.
3.5 is about 4.
This is the IEEE standard, and there are valid reasons for
it.
Mon, Mar 23 2009 8:00 AMPermanent Link

"Rita"

"Sanford Aranoff" <aranoff@analysis-knowledge.com> wrote in message
news:49C6B2D1.A9C7583D@analysis-knowledge.com...

>
> Round the final result. Don't forget that if the last digit
> is 5 you round to even.
> 4.5 is about 4.
> 3.5 is about 4.
> This is the IEEE standard, and there are valid reasons for
> it.

Yes Sanford but prior to the final output it should be $1.12345
Financial reports at board level contain both.
Bankers I'am informed have a seperate column for all the 0.5
they have made via rounding up.
Sometime ago maybe 2 years in Borland forums someone was
talking about bankers rounding, it gave a link I wish I could find
it.
On a lighter note........
One guy had written an account program for a mob guy, the
book cooking went on behind alt-del-f12 both sets spot on.
Rita

Mon, Mar 23 2009 9:58 PMPermanent Link

Sanford Aranoff
Rita wrote:
>
> "Sanford Aranoff" <aranoff@analysis-knowledge.com> wrote in message
> news:49C6B2D1.A9C7583D@analysis-knowledge.com...
>
> >
> > Round the final result. Don't forget that if the last digit
> > is 5 you round to even.
> > 4.5 is about 4.
> > 3.5 is about 4.
> > This is the IEEE standard, and there are valid reasons for
> > it.
>
> Yes Sanford but prior to the final output it should be $1.12345
> Financial reports at board level contain both.
> Bankers I'am informed have a seperate column for all the 0.5
> they have made via rounding up.
> Sometime ago maybe 2 years in Borland forums someone was
> talking about bankers rounding, it gave a link I wish I could find
> it.
> On a lighter note........
> One guy had written an account program for a mob guy, the
> book cooking went on behind alt-del-f12 both sets spot on.
> Rita

Math is based upon principles. The principle of rounding is
to minimize errors. That is why 4.3 is about 4, not 5. When
the last digit is 5, we have to alernate rounding so that
one is not unfairly weighted. Rounding to odd would cause
problems at 0, and so rounding to even is the way.
Tue, Mar 24 2009 3:50 PMPermanent Link

"Raul"

Since this started out as rounding of money type we also need to look at
that aspect  :  for example it may make sense to always round up taxes, etc.

There is a pretty cool overview of various rounding algorithms here :
http://www.diycalculator.com/popup-m-round.shtml

Raul


> Math is based upon principles. The principle of rounding is
> to minimize errors. That is why 4.3 is about 4, not 5. When
> the last digit is 5, we have to alernate rounding so that
> one is not unfairly weighted. Rounding to odd would cause
> problems at 0, and so rounding to even is the way.

Tue, Mar 24 2009 9:37 PMPermanent Link

"Rita"
This is the function I use for rounding
I use 5 decimals and 2 for the final
output.

function RoundD(x: Extended; d: Integer): Extended;
// RoundD(123.456, 0) = 123.00
// RoundD(123.456, 2) = 123.46
// RoundD(123456, -3) = 123000
var
 n: Extended;
begin
 n := IntPower(10, d);
 x := x * n;
 Result := (Int(x) + Int(Frac(x) * 2)) / n;
end;

Page 1 of 2Next Page »
Jump to Page:  1 2
Image