[squeakdev] ScaledDecimal scale after calculation
Bernhard Pieber
bernhard at pieber.com
Tue Jun 11 18:00:04 UTC 2019
Wouldn't it be possible to do fraction division and then use the scale from the resulting Fraction>>#asScaledDecimal?
 Bernhard
> Am 10.06.2019 um 18:01 schrieb Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
>
>
>
> 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
More information about the Squeakdev
mailing list
