5.3 printShowingDecimalPlaces: 2 displays '5.29' instead of'5.30'

nicolas cellier ncellier at ifrance.com
Thu Nov 22 20:35:39 UTC 2007

Tome is right. Don't use a Float

In Smalltalk, use 5.30s2.

5.3 machine representation is not 53/10 though it looks like, and though 
major Smalltalk dialects will answer true to 53/10=5.3 (i think they 
should not - see http://bugs.squeak.org/view.php?id=3374 and 

You can check it with 5.3 asTrueFraction, that is 

And if it prints 5.29s2, then it is because of 
http://bugs.squeak.org/view.php?id=5693 that you did not care to read.

* 5.3 asTrueFraction < (53/10)
* ScaledDecimal use truncated print,
=> you have the explanation.

The only thing you should try if you cannot get read of Float because of 
3rd party code is:

(5.3 asScaledDecimal: 2) roundTo: 0.01s2.


Tom Phoenix a écrit :
> On 11/22/07, Sebastian Sastre <ssastre at seaswork.com> wrote:
>> Let's supose the user enters in some
>> input widget with keyboard the '5.30' value. That will end as a Float at
>> some point.
> Why will it?
> We're talking about monetary units. If you start with a string like
> '5.30', meaning 530 monetary units, it won't "end as a Float" all by
> itself. If somebody somewhere wrote code that converted it to floating
> point, that's a bug.
> Don't be misled by what looks like a decimal point. If you're working
> with money, you don't want floating point, no matter what your
> programming language. Floating point will lose tiny bits due to
> roundoff; but money numbers are almost always integral numbers of
> cents, and you don't want to lose any of them. Floating point may be
> needed to perform some calculations along the way, but you'll use
> integers to get the books to balance.
> ObSqueak: 5.30 asFraction
> Cheers!
> --Tom Phoenix

More information about the Squeak-dev mailing list