Simple Flex Number Formatting
I’m sure this is something that most Flex developers know all about, but I was (as usual) going down the wrong rabbit hole (NumberFormatter) before I discovered NumberBase.
What I wanted was to get a number formatted like “x,xxx.xx”. I want two decimal points at all times, even when they would be zero (eg. 1,234.00).
As I mentioned, I found NumberBase, which has all sorts of cool number formatting and parsing functions.
NumberBase.formatThousands() provides the commas for the thousands, and I’m using NumberBase.formatPrecision() to add the decimal points:
var b:NumberBase = new NumberBase();
return b.formatPrecision(b.formatThousands(team.pointsTotal.toString()), 2);
I would imagine that this tip applies best to places where you are formatting numbers in ActionScript (as opposed to MXML)
November 6th, 2008 at 6:02 pm
Thank you for posting this; the information helped me solve my issue I was having.