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

Rounding down numbers using decimels

New Here ,
Nov 09, 2021 Nov 09, 2021

Hi

I am struggling to round down decimel numbers in fields to prevent the default to round up - ie: if I have 4 decimel places: 0.0000 and I type in 0.34567 - I need the field to round down the nearest decimel point: 0.3456 rather than the default of rounding up to 0.3457. 

 

Is there a way I can do this in acrobat?

TOPICS
Acrobat SDK and JavaScript
636
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

correct answers 1 Correct answer

Community Expert , Nov 09, 2021 Nov 09, 2021

Place the function as a doc-level script, and as the custom validation or calculation script of the field enter this:

if (event.value) event.value = roundDown(Number(event.value), 4);

Translate
Community Expert ,
Nov 09, 2021 Nov 09, 2021

You can use this function to do it:

 

function roundDown(v, nDecimals) {
	return Math.floor(v * Math.pow(10, nDecimals)) / Math.pow(10, nDecimals);
}

 

And you then call it like this:

 

roundDown(0.34567, 4);
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 ,
Nov 09, 2021 Nov 09, 2021

thank you Try67 - how do I place this in the text field properties?

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 ,
Nov 09, 2021 Nov 09, 2021

Place the function as a doc-level script, and as the custom validation or calculation script of the field enter this:

if (event.value) event.value = roundDown(Number(event.value), 4);

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 ,
Nov 09, 2021 Nov 09, 2021
LATEST

Brilliant - works perfectly! Thank you so much for your excellent skills!! 🙂

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