method EditFocusChange(oEditFocusChangeEvent) class InvoicingScr
local oControl as Control
local lGotFocus as logic
Local nGSTInc, nGSTPaid
oControl := IIf(oEditFocusChangeEvent == NULL_OBJECT, NULL_OBJECT, oEditFocusChangeEvent:Control)
lGotFocus := IIf(oEditFocusChangeEvent == NULL_OBJECT, FALSE, oEditFocusChangeEvent:GotFocus)
//Put your changes here
nGSTPaid := gGSTRate/100
nGSTInc := 1 + nGSTPaid
my calculator gives me the following result:
804.55 * 1.1 = 885,01
The Windows calculator instead returns
804.55 * 1.1 = 885.005
VO is ok - but maybe you have other rules for tax calculations?
P.S. why you don't type your variables nGSTInc, nGSTPaid?
My apologies Wolfgang, I meant no disrespect, of course I was going to try it, I was just thinking out loud. I don't get the 0.01 bit, as I thought the whole idea of the Round function was to do exactly what it said it would. I didn't think it required an undocumented "fudge factor" in order to make it work, WHICH YOUR CODE DID, So, thank you very very much again Wolfgang.
Thanks very much Karl-Heinz. I was thinking round to 2 decimal places because that's how dollars and cents work, so the logic of rounding to 1 place seems strange to me. But thanks very much for the explanation. I may not understand the logic, but I'll know how to use it in future!
But according to #12740 you DON'T want dollars/cent, you want dollars/dime (is that the word?) That's the reason you need the "1", like K-H wrote. _Showing_ the trailing zero is a display thing, not a mathematical one.
No Karl, I needed the cents. In that example the rounding was to round to the next whole Dollar/Cent value e.g.
855 dollars, Zero cents. For example
855.01 is 855 dollars and 1 cent. We don't have 1 cent pieces any more. Our next valid D/C amount is 855.05 (5 cents) then 855.10 (10 cents) in other words it must end in 0, 5 or10. I hope that makes some sense.
Where's the middle ground? It can only either be 10 cents or an even dollar, no 5 cents (and by 5 cents I'm including 15, 25, 35, 45...95 cents as well.)
How am I to code for this? How am I to know if something entered by the end user needs to be rounded to 2 or 1? Rounding by 1 means I could be out by as much as 6 cents per transaction, which over time throws all the figures out massively.
Don't use the Round function. Just chop off any decimal digits after the 2nd decimal position.
FUNCTION NoRound(fValue AS USUAL) AS REAL8 PASCAL
LOCAL c AS STRING
LOCAL dwDecPos AS DWORD
c := alltrim(AsString(fValue))
dwDecPos := At2(".", c)
RETURN Val(SubStr3(c, 1, dwDecPos-1) + "." + SubStr3(c, dwDecPos+1,2))