Skip to main content
Participant
Nov 9, 2021 1:13 PM UTC
Answered

Rounding down numbers using decimels

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?

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Nov 9, 2021 1:27 PM UTC

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

4 replies

try67
Community Expert
Community Expert
Nov 9, 2021 1:19 PM UTC

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
Participant
Nov 9, 2021 1:24 PM UTC

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

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Nov 9, 2021 1:27 PM UTC

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