<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Wed, Jul 31, 2019 at 6:06 AM Levente Uzonyi <<a href="mailto:leves@caesar.elte.hu">leves@caesar.elte.hu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">On Wed, 31 Jul 2019, David T. Lewis wrote:<br>
<br>
> On Wed, Jul 31, 2019 at 11:53:38AM +0000, Rein, Patrick wrote:<br>
>> Hi everyone,<br>
>> <br>
>> a student recently encountered the following behavior:<br>
>> <br>
>> fraction := 5 / 9.<br>
>> (fraction* 100) truncateTo: 0.01. ???55.550000000000004"<br>
>> fraction:= 1/18.<br>
>> (fraction * 100) roundTo: 0.01. ???5.5600000000000005"<br>
>> <br>
>> This is not what I would expect from #truncateTo: or #roundTo: even when using Floats (especially roundTo:).<br>
>> <br>
>> Is this what we want or an open issue? I have not found any test covering the protocol.<br>
>><br>
><br>
> The results are unexpected, but not wrong.<br>
><br>
> Why unexpected? When I look at the expression, I intuitively expect<br>
> it to perform decimal arithmetic, and it does not do that.<br>
><br>
> Why not wrong? 0.01 is a float, even though it may have been intended<br>
> as an exact decimal number by the writer. Mixing float values in any<br>
> arithmetic expression produces an inexact float result, as it should.<br>
><br>
> To get a result that is both correct and intuitively right, the expression<br>
> might better be written like this:<br>
><br>
>  5 / 9 * 100 truncateTo: (1/100) ==> (1111/20)<br>
<br>
I think ScaledDecimal is a better fit, as it gives a decimal result:<br>
<br>
5 / 9 * 100 truncateTo: 0.01s "==> 55.55s2"<br></blockquote><div><br></div><div>To be precise, it still gives you the same result as the fraction result, but it look like you would expect (i.e., it prints as a decimal, properly truncated).</div><div><br></div><div>But, yes, probably a better fit.</div><div><br></div><div>-cbc</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">
<br>
<br>
Levente<br>
<br>
><br>
> Dave<br>
<br>
</blockquote></div></div>