NumberFormatter.as 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (c) 2008, Adobe Systems Incorporated
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Adobe Systems Incorporated nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. package com.adobe.utils
  28. {
  29. /**
  30. * Class that contains static utility methods for formatting Numbers
  31. *
  32. * @langversion ActionScript 3.0
  33. * @playerversion Flash 9.0
  34. * @tiptext
  35. *
  36. * @see #mx.formatters.NumberFormatter
  37. */
  38. public class NumberFormatter
  39. {
  40. /**
  41. * Formats a number to include a leading zero if it is a single digit
  42. * between -1 and 10.
  43. *
  44. * @param n The number that will be formatted
  45. *
  46. * @return A string with single digits between -1 and 10 padded with a
  47. * leading zero.
  48. *
  49. * @langversion ActionScript 3.0
  50. * @playerversion Flash 9.0
  51. * @tiptext
  52. */
  53. public static function addLeadingZero(n:Number):String
  54. {
  55. var out:String = String(n);
  56. if(n < 10 && n > -1)
  57. {
  58. out = "0" + out;
  59. }
  60. return out;
  61. }
  62. }
  63. }