[Newbies] roundTo: doesn't appear to work

Bert Freudenberg bert at freudenbergs.de
Tue Nov 20 00:34:56 UTC 2012


On 20.11.2012, at 00:22, Joseph J Alotta <joseph.alotta at gmail.com> 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 -




More information about the Beginners mailing list