I came across this weird behavior while using NumberFormatter in AS3.
It's important to understand that I need to use NumberBaseRoundType.UP
because I need to use NumberBaseRoundType.DOWN
when applying a credit.
Considering the rounding precision that has a value of 2, I guess the NumberFormatter shouldn't change my number. In the example below, 2.43 once formatted become 2.44..!
So the Math.pow(...)
is not the solution I'm looking for PLUS, I am very interested to understand what and why this is happening. THANKS!
var roundUp:NumberFormatter = new NumberFormatter();
roundUp.rounding = NumberBaseRoundType.UP;
roundUp.precision = 2;
trace(roundUp.format(2.41)); // Output : 2.41
trace(roundUp.format(2.42)); // Output : 2.42
trace(roundUp.format(2.43)); // Output : 2.44 <-- ???
trace(roundUp.format(2.44)); // Output : 2.44
trace(roundUp.format(2.45)); // Output : 2.46 <-- ???
trace(roundUp.format(2.46)); // Output : 2.46
This is not a complete answer. But to start off with which NumberFormatter class are you using (what's the package it comes from). Some of the source is available, some of it is contained in the player itself and isn't accessible, but in looking at the on included in Spark from the 4.6 framework it includes this class level comment that gives some insight:
Ultimately though it states that the player uses the underlying OS in some way to achieve the formatting. It is certainly a strange problem but I'd be surprised if this wasn't ever caught before and an explanation hasn't been posted or at least a bug report if it is in fact an issue in flash player. Some more details on your SDK version and player version may help, also have you tried fiddling with either of these is there any change in results?
Also depending on what you're attempting to achieve you may be able to just get around the issue by writing your own class to deal with doing the formatting for this case if it's just a one off scenario that you need to deal with this, if it's more of a system wide used thing that needs more of the functionality of the NumberFormatter class I could understand wanting to resolve the underlying issue.