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!

Nesa Nurani
Community Expert
Community Expert
March 10, 2022

Code is working as intended, if you enter .1234567 code won't work at all, so I don't know how you got it to round it to .123457?

You need to be specific when you asking for help, so you will entering numbers as .1234567 do you want result to be .123456 or 0.123456?