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

How do I get my form calculation to round to 2 decimal places?

New Here ,
Dec 05, 2017 Dec 05, 2017

Hi,

I need my total value amount in my form to display two decimal places. At the moment it shows as .00 no matter what numbers I put in.

The script I am using is this:

(function () { 

 

    // Get the field values, as numbers 

    var v1 = +getField("ccc").value; 

    var v2 = +getField("ddd").value;

 

    if (v1 !== 0) { 

        event.value = v1 * v2 * 220; 

    } else { 

        event.value = ""; 

    } 

 

})();

Please help! Thanks in advance.

TOPICS
Acrobat SDK and JavaScript , Windows
680
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
LEGEND ,
Dec 05, 2017 Dec 05, 2017

Change that one line to:

event.value = util.printf("%.2f", v1 * v2 * 220);

If that doesn't work, please give examples of the values for the ccc and ddd fields, along with the displayed result.

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
New Here ,
Dec 05, 2017 Dec 05, 2017

Hi, thanks for your reply but that didn't work.

ccc is calculated by:

(function () { 

 

    // Get the field values, as numbers 

    var v1 = +getField("aaa").value; 

    var v2 = +getField("bbb").value;

 

    if (v2 !== 0) { 

        event.value = v1 / v2 ; 

    } else { 

        event.value = ""; 

    } 

 

})();

So i have aaa, bbb, ccc, ddd, eee. On my phone in Reader when these equal 65, 1.35, 48, and 25 respectively I get eee to equal 264,814.8

On my desktop when these same values are entered eee displays as 264,000.00

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 ,
Dec 05, 2017 Dec 05, 2017

What do you have set as a format on the calculated fields? I'd suggest removing all formatting. Then let us know what you  got.

Sounds like Reader is having an issue. Could be extra code that's in there.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
New Here ,
Dec 05, 2017 Dec 05, 2017
LATEST

Hi

I had the formatting set to:

Number

Decimal Places: 2

Separator Style: 1,234.56

Currency Symbol: None

and that's it.

I've just reset them all to "none" and it's still not working.

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