[squeak-dev] ScaledDecimal scale after calculation

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Mon Jun 10 16:01:25 UTC 2019


Le lun. 10 juin 2019 à 17:33, Bernhard Pieber <bernhard at pieber.com> a
écrit :

> Hi,
>
> For my accounting I like to use ScaledDecimal, knowing it is just a
> fraction with a scale.
>
> I just stumbled upon the following:
> 0.1s * 0.5s. "0.0s1"
>
> The underlying fraction is correct (1/20). However, the scale is 1, which
> surprised me. Shouldn't the scale be 2?
>
> Maybe... But then what scale to use for division?

In VA Smalltalk which I use for accounting as well the multiplication
> results in 0.05s2, which I had expected. (It prints as 0.05, though.)
>
> Fraction>>#asScaledDecimal even has the needed code:
> "Convert the receiver to a ScaledDecimal.
>         If there is a finite decimal representation of the receiver, then
> use the exact number of decimal places required.
>         Else, use a default number of decimals."
>
> (1/20) asScaledDecimal. "0.05s2"
>
> Some other strangeness:
> 3s scale. "0"
> 3 asScaledDecimal scale. "0"
> 3s asScaledDecimal scale. "8"
>
> ScaledDecimal>>#asScaledDecimal should probably just return self.
>
> +1

What do you think?
>
> - Bernhard
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20190610/e7f139ae/attachment.html>


More information about the Squeak-dev mailing list