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.
Screenshot:
Enter arbitrary number to see the result method “addLeadingZero.”
Methods:
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.
Parameters:
n:Number The number that will be formatted.
Returns:
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="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx:Script>
- <![CDATA[
- import com.adobe.utils.NumberFormatter;
- ]]>
- </mx:Script>
- <mx:VBox width="100%" height="100%">
- <mx:HBox>
- <mx:Label text="Number to be formatted" />
- <mx:TextInput id="number" text="9"/>
- </mx:HBox>
- <mx:Text text="addLeadingZero:{NumberFormatter.addLeadingZero(Number(number.text))}"/>
- </mx:VBox>
- </mx:Application>

September 7th, 2008
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed
[...] is the summary of the Package com.adobe.utils, include ArrayUtil, DirectoryUtil, DateUtil, IntUtil, NumberFormatter, StringUtil and XMLUtil [...]