Skip to Content »

FlashApe » Flex binding to numbers and increment issue

 Flex binding to numbers and increment issue

  • March 5th, 2008
  • 3:40 pm

Anyone know what's going on here? I have a property on a model that is bindable:

Actionscript:
  1. [Bindable]
  2. public var currentAmount:Number = 0;

I have a command that increments that value, by some fractional amount:

Actionscript:
  1. [Bindable]
  2. model.currentAmount += 1.25;

What's happening is I am winding up with values like 1.25000000000000000001. Even wierder is that the last digit increments with how many times the variable is incremented, so so if I add another .50 to the previous value, I wind up with 1.75000000000000000002.

Currently I'm using a setter and fixing the problem by using toFixed(2), but that seems very retarded:

Actionscript:
  1. _currentAmount = newValue;
  2. var s:String = _currentAmount.toFixed(2);
  3. _currentAmount = Number(s);

I'm sure if this was a bug it would be pretty well known by now, but I can't seem to find anything on google, so I'm guessing I'm doing something wrong. Anyone have an idea?

3 People had this to say...

Gravatar
  • Am
  • March 6th, 2008
  • 4:04 am

i saw that before, check this link which registers a bug to flash player version 10 (if it's on 10 it might be also on 9),
bugs.adobe.com

and also here

Gravatar
  • rich
  • March 6th, 2008
  • 8:19 am

yeah, at the second link you left there is this wikipedia link saying that it's an issue with floats in general. Oh well, guess I have no choice about the workaround now.

Gravatar
  • Tink
  • April 19th, 2008
  • 11:09 am

You could multiply it by 100, floor it, the divide by 100 in the binding?

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>