as3corelib Tutorial:How to Use NumberFormatter Class in Flex

Finder-128x128 NumberFormatter class contains static utility methods for formatting Numbers. Now, there is a mere method defined. The method addLeadingZero “Formats a number to include a leading zero if it is a single digit between -1 and 10.”  , simple but very useful. :)

I found codes “returnString+=NumberUtil.addLeadingZero(dateToFormat.getDate());” from internet. We can see that this is what we need when we do such things, to format year, month, day, hour, minute, second or others whatever.

Search-256x256 Demo | DownloadDownload Full Project


Enter arbitrary number to see the result method “addLeadingZero.”



1. addLeadingZero()

public static function addLeadingZero(n:Number):String

Formats a number to include a leading zero if it is a single digit between -1 and 10.


n:Number The number that will be formatted.


String A string with single digits between -1 and 10 padded with a leading zero.

The following is full source code of NumberFormatter Demo.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" layout="absolute">
			import com.adobe.utils.NumberFormatter;

	<mx:VBox width="100%" height="100%">
			<mx:Label text="Number to be formatted" />
			<mx:TextInput id="number" text="9"/>

		<mx:Text text="addLeadingZero:{NumberFormatter.addLeadingZero(Number(number.text))}"/>

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

One Response to “as3corelib Tutorial:How to Use NumberFormatter Class in Flex”

  1. [...] is the summary of the Package com.adobe.utils, include ArrayUtil, DirectoryUtil, DateUtil, IntUtil, NumberFormatter, StringUtil and XMLUtil [...]

Leave a Reply