These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Numeric Formatting in JavaScript

DrDave
Registered: Apr 21 2009
Posts: 6
Answered

I'm using the following in a validation event in LiveCycle Designer 8.

var MBn = (iSizeN / 1383.27)/ 1024;

The result is a digit with around 10 decimal places.

1) What do I need to do so that the result is only 2 decimal places?

2) How do I then convert the 2-decimal place number to a text string so that I can use it in a message? Note that I still need access to the MBn variable so the string variable would be MBs.

Thank you for the help.

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You've got a couple of differnt things going. First, the display format is controled with a "Picture Clause" which can be set on the "Object" tab for the field.

Second, in JavaScript you can use the "util.printf()" function to format a number into text for display. This is an Acrobat JavaScript function, but it will work just fine in a LiveCycle JavaScript.
There is also a "Format()" function in FormCalc that uses a Picture Clause to format data.

So there are a number of options.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
FormCalc also has the "Round()" funciton for rounding results, the "Floor()" function that can truncate a number, and the 'Ciel()' function to trunctate to the next larger number.

George Kaiser

DrDave
Registered: Apr 21 2009
Posts: 6
Thank you for pointing this out. That will be useful.