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

Tom Phoenix rootbeer at redcat.com
Thu Nov 22 19:58:31 UTC 2007

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


--Tom Phoenix

More information about the Squeak-dev mailing list