Problem with roundTo: (Actually with *)

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

Problem with roundTo: (Actually with *)

summae3443
In Squeak 4.3 I print "(7/5) roundTo: 0.01" and get "1.4"
however,
In Squeak 4.4 I print "(7/5) roundTo: 0.01" and get "1.4000000000000001"

Am I doing something to cause this change? Or, is this the result of inflation :)

Dan Norton

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

Re: Problem with roundTo: (Actually with *)

Bert Freudenberg

On 03.07.2013, at 13:56, [hidden email] wrote:

> In Squeak 4.3 I print "(7/5) roundTo: 0.01" and get "1.4"
> however,
> In Squeak 4.4 I print "(7/5) roundTo: 0.01" and get "1.4000000000000001"
>
> Am I doing something to cause this change? Or, is this the result of inflation :)

No, it's the result of more precise Float printing. Consider this:

((7/5) roundTo: 0.01) = 1.4
==> false

((7/5) roundTo: 0.01) = 1.4000000000000001
==> true


For printing with a reduced precision you should not use roundTo but this:

7/5 printShowingDecimalPlaces: 2
==> '1.40'

7/5 printShowingMaxDecimalPlaces: 2
==> '1.4'

- Bert -


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