Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

util.printf()

Community Expert ,
Nov 19, 2016 Nov 19, 2016

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.


Acrobate du PDF, InDesigner et Photoshoptographe
TOPICS
Acrobat SDK and JavaScript
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 19, 2016 Nov 19, 2016

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.

Translate
LEGEND ,
Nov 19, 2016 Nov 19, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2016 Nov 19, 2016

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.


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2016 Nov 20, 2016
LATEST

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.


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines