I don't believe roundTo: is the method you're looking for. <div>I've been confused by this before. </div><div><br></div><div><div>roundTo: quantum </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"Answer the nearest number that is a multiple of quantum."</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>^(self / quantum) rounded * quantum</div><div><br></div><div>Maybe try this:</div><div></div></div><div><br></div><div><div>roundedToFloat: quantum </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>"Round to decimal places."</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| aReciprocal |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>aReciprocal := quantum reciprocal rounded.</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>^(self * aReciprocal) rounded / aReciprocal asFloat</div><div><br></div><div><br></div><div><br></div><div class="gmail_quote">On Sun, May 6, 2012 at 9:20 PM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, 6 May 2012, Chris Muller wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
( 0.9580000000000001 roundTo: 0.0001) = 0.9580 "false"<br>
</blockquote>
<br>
Still didn't look at the code, but 0.0001 is also a Float and it doesn't have an exact representation in base 2. The following works as expected:<br>
(0.9580000000000001 roundTo: 0.0001s4) "0.9580s4"<br>
(0.9580000000000001 roundTo: 1/10000) "(479/500)"<br>
<br>
<br>
Levente<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
<br>
On Sun, May 6, 2012 at 8:55 PM, Levente Uzonyi <<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sun, 6 May 2012, Chris Muller wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
With the latest trunk updates, I'm having trouble rounding to my<br>
desired precision:<br>
<br>
0.9580000000000001 roundTo: 0.0001 " 0.9580000000000001"<br>
<br>
In Squeak 4.3 I get what I expect:<br>
<br>
0.9580000000000001 roundTo: 0.0001 " 0.958"<br>
<br>
<br>
</blockquote>
<br>
I'm pretty sure it's just a difference in printing. 0.958 is unlikely to<br>
have an exact base 2 representation.<br>
<br>
<br>
Levente<br>
<br>
</blockquote>
<br>
</blockquote>
<br><br>
<br></blockquote></div><br></div>