Skip to main content
Participant
March 9, 2022
Question

Make a number go to 6 decimal places and not round

  • March 9, 2022
  • 2 replies
  • 1229 views

Is there a custom validation script that will only allow 6 decimal places to show and not round if more are entered?

This topic has been closed for replies.

2 replies

JR Boulay
Community Expert
Community Expert
March 9, 2022

You should use this AFNumber_Format:

if (event.value && !isNaN(Number(event.value))) {AFNumber_Format(6, 0, 0, 0, "", false);}

 

The Acrobat provided forms function call:

AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)

nDec = number of decimals
sepStyle = separator style 0 = 1,234.56 / 1 = 1234.56 / 2 = 1.234,56 / 3 = 1234,56 /
negStyle = 0 black minus / 1 red minus / 2 parens black / 3 parens red /
currStyle = reserved
strCurrency = string of currency to display
bCurrencyPrepend = true = pre pend / false = post pend

Acrobate du PDF, InDesigner et Photoshopographe
Inspiring
March 9, 2022

That is not going to work, firstly it will round number which OP said he doesn't want, secondly once entered it won't work anymore because decimal point is removed.

JR Boulay
Community Expert
Community Expert
March 9, 2022

Oops!

I read too fast.

Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Community Expert
March 9, 2022

Yes, use this:

var num = event.value;
var dec = num.match(/^-?\d+(?:\.\d{0,6})?/)[0];
event.value = dec;

Participant
March 10, 2022

Hi Nesa,

 

I apprecaite the response! The script works, however when testing I found that when entering a value without a number to the left of the decimal and entering more than six decimal places, the value will round (i.e. .1234567 will round to .123457 vs 0.1234567 will round to 0.123456).

 

Thank you in advance for the help!

Participant
March 10, 2022

If possible when entering .1234567 I would want the result to be 0.123456


To clarify, I want the original script to work as intended and have .1234567 to round to 0.123456.