Rounding issue
Rounding issue
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!
Rounding issue
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.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Rounding issue
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.
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.
Rounding issue
OK, then i misread your sample...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Rounding issue
Am I correct in thinking this solution won't work for 5 cents (0.05)? I can live with it if that's the case...
Rounding issue
Jeff
Multiply by 2, round to 1 decimal and then divide by 2 ?
Robert
Multiply by 2, round to 1 decimal and then divide by 2 ?
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
Rounding issue
Hi Jeff,BiggyRat wrote:Am I correct in thinking this solution won't work for 5 cents (0.05)? I can live with it if that's the case...
what´s the problem with 0.05 ?
? Round ( 0.05 , 2 ) // ok 0.05
? Round ( 0.05 , 1 ) // ok 0.1
regards
Karl-Heinz
Rounding issue
Hi Karl-Heinz, 5 cents is 5 cents - accounting wise. If a user enters in a Dollar value and a Quantity, then the tax makes the amount end in 4 cents (0.04).
Round ( 0.04 , 2 ) // 0.04
Round ( 0.04 , 1 ) // 0.0
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.
Regards,
Jeff
Round ( 0.04 , 2 ) // 0.04
Round ( 0.04 , 1 ) // 0.0
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.
Regards,
Jeff
Rounding issue
Jeff
Did you try what I suggested?
Robert
Did you try what I suggested?
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Rounding issue
Don't use the Round function. Just chop off any decimal digits after the 2nd decimal position.
Code: Select all
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))