Yes, there's a bug when converting Floats to Scaled Decimals. It's not precise. This works:
a := ScaledDecimal newFromNumber: 618/100 scale: 4. b := ScaledDecimal newFromNumber: 5 scale: 4. a / b "1.2360s4"
This is the problem:
6.18 asFraction
(869757678035927/140737488355328)
instead of (6.18 * 10e4) rounded / 10e4
(309/50)
So when converting from a Float it should be rounded to scale, IMHO.
You should report this (best along with the fix) on the squeak bug tracker. And because it's not a Seaside problem, we should continue the discussion to squeak-dev.
- Bert -
Am 02.02.2006 um 15:13 schrieb Dmitry Dorofeev:
Hi,
Assuming I have prices with 2 digits after dot I want to calculate VAT with 4 digits precision. VAT May be shown still rounded to 2 digits, but some clients want to see even 4 digits after dot !!! With high turn over made from small sells it is some real money due to rounding errors :-)
I made some tests and found a funny example:
a := ScaledDecimal newFromNumber: 6.18 scale: 4. b := ScaledDecimal newFromNumber: 5 scale: 4. a / b 1.2359s4 a / b printShowingDecimalPlaces: 4 '1.2360' 6.18 / 5.0 1.236
why a / b shows 2.2359s4 ? but (a / b printShowingDecimalPlaces: 4) shows correct answer It makes me nervious....
Thanks.
David T. Lewis wrote:
in Wed, Feb 01, 2006 at 02:51:42PM +0300, Dmitry Dorofeev wrote:
Thanks,
this one looks practical. I am sad there is no Money in Squeak though...
Don't be sad, there is ScaledDecimal in Squeak :) Float is *not* appropriate for financial calculations, but ScaledDecimal should be OK. And #printShowingDecimalPlaces: will work with ScaledDecimal also: 123.3453 asScaledDecimal printShowingDecimalPlaces: 2. ==> '123.35' Dave
squeak-dev@lists.squeakfoundation.org