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)

Tags: , , , ,

One Response to “Simple Flex Number Formatting”

  1. Kathie in San Diego Says:

    Thank you for posting this; the information helped me solve my issue I was having.

Leave a Reply