3 Replies Latest reply on Nov 20, 2016 3:11 AM by JR_Boulay

    util.printf()

    JR_Boulay Adobe Community Professional

      Hi.

       

       

      I know how to use util.printf() to get a number formated as: 1234.56

       

      n = util.printf("%.2f", n);
      

       

       

      What I need is a number formated as: 1234,56

      With a comma instead of a dot.

       

       

      How can I do that?

      Where can I find some infos since I cannot find nothing in the JS Reference?

       

      Thank you.

        • 1. Re: util.printf()
          gkaiseril MVP & Adobe Community Professional

          I would add the "nDec" parameter with a value of ",2".

           

          var nValue = 123.56;

          var nDec = ",2";

          var cFlags = "";

          var nWidth = "";

          var nPrecision = ".2";

          var cConvChar = "f";

          var cFormat = "%" + nDec + cFlags + nWidth + nPrecision + cConvChar;

          console.println("cFormat: " + cFormat);

          var cValue = util.printf(cFormat, nValue);

          console.println("nDec " + nDec + " — Period separated, comma decimal point : " + cValue);

           

          It is explained under the "util" object and the "printf" method.

          • 2. Re: util.printf()
            JR_Boulay Adobe Community Professional

            Great great great, it works fine.

            In fact, the French format is closest if the "nDec" parameter have a value of ",3".

             

            Thank you very much, I learned something today.

             

            • 3. Re: util.printf()
              JR_Boulay Adobe Community Professional

              the French format is closest if the "nDec" parameter have a value of ",3".

              It is close but not satisfactory since French format requires blank spaces as separators:

               

              10 234 567 890,55

               

              Since French separators are not available directly as a format I use a "dot separators" format, and I replace dots by blank spaces:

               

              n = util.printf("%,2.2f",n).toString().replace(/\./gim," ");
              

               

              And the goal is reached!

               

              Thank you once again.

               

               

              En français :

              Le format de nombre français n'étant pas disponible directement dans les formats, la ruse dans la formule ci-dessus consiste à utiliser un format qui place des points comme séparateurs de milliers, et à remplacer à la volée les points par des espaces.