3 Replies Latest reply on Aug 12, 2010 9:02 AM by rtalton

    Number Formatting

    samschauhan

      I want to format a number such that the preceding 0s are trimmed:

       

      00079 should be 79.

       

      Also I dont want the thousands separator to appear in bigger numbers:

       

      0007989999999 should be 7989999999 and not 7,98,99,99,999.

       

      Let me know the solution folks.

       

      Thanks,

      SAM

        • 1. Re: Number Formatting
          BhaskerChari Level 4

          Hi Sam,

           

          You can make use of the function below to trim leading zeroes from a Number which is a String...

           

          private function trimZeroes():void
                    {
                     var strNum:String = "0007989999999";
                    
                     for(var i:int=0;i<strNum.length;i++)
                     {
                      if(strNum.charAt(0) == "0")
                      {
                       strNum = strNum.substring(1,strNum.length);
                      }
                      else
                      {
               break;            
                      }
                     }
                    }

           

           

          You can then Cast it to Number after Trim..

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: Number Formatting
            samschauhan Level 1

            Thanks.

            • 3. Re: Number Formatting
              rtalton Level 4

              Just use the Number class itself:

               

              Number('00079')// outputs 79