[squeak-dev] ScaledDecimal scale after calculation
Bernhard Pieber
bernhard at pieber.com
Mon Jun 10 15:33:18 UTC 2019
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?
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.
What do you think?
- Bernhard
More information about the Squeak-dev
mailing list
|