1 Reply Latest reply on Apr 13, 2011 9:04 AM by Lee Burrows

    Format negative numbers

    jfb00 Level 3

      Hi All,

      How can I format a negative number in red color? Like (2323)

      I have this function:


       public static function formatNumber(val:Number):String
              var numberFormatter:NumberFormatter = new NumberFormatter();
              numberFormatter.precision = 0;
              numberFormatter.useNegativeSign = false;
              return numberFormatter.format(val);


      I am able to display in parenthesis but i don't see any property for style.

      Any ideas?




        • 1. Re: Format negative numbers
          Lee Burrows Level 4



          you could add a style to the text element that displays your number, eg:


          in css:


          .blackText {

          color: #000000;


          .redText {

          color: #FF0000;



          for label (or other text element):


          <s:Label styleName="{numValue&lt;0 ? 'redText' : 'blackText'}" text="{numValue.toString()}" .... />


          (note use of "&lt;" rather than "<" because code is inside {} )


          and lastly ensure numValue is bindable:



          private var numValue:Number;


          Now, instead of updating the label directly with the formatted string, update numValue instead (with a Number)