Go to content Go to navigation Go to search

Float / Integer bug in Flash MX 2004 · Monday October 23, 2006 by Rudolf Vavruch

Trying to fix a bug in an old piece of Flash, I came across some wierdness in this code:


Number(x) * 100 − y

x is a string representing a float. y is an integer.

It works great until Number(x) * 100 == y; then, instead of the result being 0—as you would expect, the result is a hugely negative number.

Like −2.8421709430404e−14 if x and y = 230.

The negative number is not arbitary, it seems to give the same value the input values.

I did however come up with a fix:


Math.floor(Number(x)) * 100 − y

Using Math.floor() to convert Number(x) into an integer, the weirdness fades away.

Interesting, but it is ActionScript 1.0 and I do not have spare time to play any further.

Commenting is closed for this article.