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

Rounding down numbers using decimels

New Here ,
Nov 09, 2021 Nov 09, 2021

Copy link to clipboard

Copied

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

Views

271

Translate

Translate

Report

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);

Votes

Translate

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

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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