Skip to main content
Participant
November 9, 2021
Answered

Rounding down numbers using decimels

  • November 9, 2021
  • 1 reply
  • 739 views

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 has been closed for replies.
Correct answer try67

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

1 reply

try67
Community Expert
Community Expert
November 9, 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);
Participant
November 9, 2021

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 9, 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);