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

Make a number go to 6 decimal places and not round

New Here ,
Mar 08, 2022 Mar 08, 2022

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

TOPICS
How to , JavaScript , PDF forms
1.2K
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 ,
Mar 09, 2022 Mar 09, 2022

Yes, use this:

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

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 ,
Mar 09, 2022 Mar 09, 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!

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 ,
Mar 09, 2022 Mar 09, 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?

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 ,
Mar 10, 2022 Mar 10, 2022

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

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 ,
Mar 10, 2022 Mar 10, 2022
LATEST

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

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 ,
Mar 09, 2022 Mar 09, 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
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
Enthusiast ,
Mar 09, 2022 Mar 09, 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.

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 ,
Mar 09, 2022 Mar 09, 2022

Oops!

I read too fast.


Acrobate du PDF, InDesigner et Photoshopographe
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