roundTo: doesn't appear to work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

roundTo: doesn't appear to work

Joseph Alotta
n := 2.12435454313

n roundTo: 3. ==> 3
2 roundTo: n ==> 2.12435454313


Am I doing something wrong?
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: roundTo: doesn't appear to work

Bert Freudenberg
On 20.11.2012, at 00:22, Joseph J Alotta <[hidden email]> wrote:

> n := 2.12435454313
>
> n roundTo: 3. ==> 3
> 2 roundTo: n ==> 2.12435454313
>
>
> Am I doing something wrong?

#roundTo: rounds to the closest multiple of its argument. Appears to work fine in the examples you gave.

Perhaps you meant this:

2.12435454313 roundTo: 0.001
==> 2.124

Be aware that this might print as 2.124000000000001 for certain numbers. If you really want 3 decimal places, use:

2.12435454313 printShowingMaxDecimalPlaces: 3
==> '2.124'

or:

2.12435454313 printShowingDecimalPlaces: 3
==> '2.124'

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners