4 Replies Latest reply on Aug 5, 2010 10:20 AM by gkaiseril

    Adding commas to numbers when saved to fdf

    1stSniff-SMP

      I suspect that the answer to this is right in front of me, but I just can't seem to find it ...


      What is the most efficient way to consistently add commas to numbers so that they display properly when concatenated into a string ...

       

      an illustration

      Field1: Style => Colonial

      Field2: Area => 3,500 (Typically input by user without commas, but formatted field displays commas by using format tab options)

      Field3: City => Providence

       

      I'd like to be able to combine these values into a single statement  ... easy enough using simple concatenation of getField().value ... but

       

      I want result to be "3,5000 SF Colonial in Providence"   NOT   "3500 SF Colonial in Providence"

       

      Can anybody please help me with an efficient solution that is easily implemented?

       

      Thank you very much!

      -Scott

        • 1. Re: Adding commas to numbers when saved to fdf
          try67 MVP & Adobe Community Professional

          Try using valueAsString instead of value.

          • 2. Re: Adding commas to numbers when saved to fdf
            1stSniff-SMP Level 1

            I have tried that, but I believe that the number is being stored as just digits with no commas ... so that is the valueAsString value as well.

             

            How do I have the commas added to the actual stored value when it is input, rather than simply applied to the display value for that entry field. Hope that question makes sense.

             

            Thank you.

            • 3. Re: Adding commas to numbers when saved to fdf
              try67 MVP & Adobe Community Professional

              You'll need to create your own validation script. But there might be a way

              to get the formatted value directly.

              • 4. Re: Adding commas to numbers when saved to fdf
                gkaiseril MVP & Adobe Community Professional

                You can use the 'util.printf(cFormat, cValue1, [cValue2, [cValue3, ...]])' to format the display string. A custom calculation scriplt similar to:

                 

                 

                // get the values to display
                var nArea = this.getField('Area').value;
                var cStyle = this.getField('Style').value;
                var cCity = this.getField('City').value;

                // end of variables
                // build format string to display of values
                var cFormat = '%,0 .0f'; // format sq ft variable
                cFormat += ' SF '; // add literal " SF "
                cFormat += '%s'; // format for style variable
                cFormat += ' in '; // literal  " in "
                cFormat += '%s'; // format for city variable

                // end of build format string

                // use cFromat string to dispaly the formatted nArea, cStyle and cCity
                event.value = util.printf(cFormat, nArea, cStyle, cCity);

                 

                I have split the code so you can follow how the format control string is built up for each field and literal inserted into the formatted string.

                 

                A one line of code solution could be:

                 


                event.value = util.printf('%,0 .0f SF %s in %s',  this.getField('Area').value, this.getField('Style').value, this.getField('City').value);