On Fri, Sep 7, 2012 at 10:34 AM, Nicolas Cellier
<[email protected]> wrote:
> 2012/9/7 Denis Kudriashov <[email protected]>:
>> Thank's for your answer.
>> Only one of your solutions works:
>> (146.015 asMinimalDecimalFraction roundTo: 1/100) asFloat => 146.02
>>
>> Others not works:
>>
>> (146.015 * 100.0) rounded / 100.0 => 146.01
>> (146.015 asFraction roundTo: 1/100) asFloat => 146.01
>>
>>
>
> That's expected, '146.015' asFloat is already smaller than
> (146015/1000) so if you convert the float value asFraction or
> asScaledDecimal, it's too late, rounding error is already there. You
> have to use Fraction, ScaledDecimal or FixedDecimal of Chris right
> from the beginning, and don't use Float at all.
>
If you used ScaledDecimal, you will need to make sure that all parts
of it are ScaledDecimal, too - no mixing of Floats anywhere:
This doesn't work:
146.015s3 roundTo: 0.01 => 146.01
but this does
146.015s3 roundTo: 0.01s2 => 146.02s2
-Chris