Skip to main content
Participant
December 29, 2021
Answered

Truncating Decimals into Integer

  • December 29, 2021
  • 1 reply
  • 993 views

Hello,

 

I am currently using this script to truncate decimals into an integer:

 

event.value = event.value.toString().replace(/(^.*\.\d{0}).*$/,"$1");

 

This is a minor request, but how can I modify this script so that the decimal point does not appear at the end?

Example of current result: 36.

Example of desired result: 36

 

Any other guidance for formatting script to "drop" decimals is also appreciated! Thank you in advance.

This topic has been closed for replies.
Correct answer Thom Parker

There are many different ways to modify decimal numbers. From mathematical rounding to text manipulation. 

If all you want to do is to remove the decimal, then use the Math.floor() function.

 

event.value = Math.floor(event.value);

 

  

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 29, 2021

There are many different ways to modify decimal numbers. From mathematical rounding to text manipulation. 

If all you want to do is to remove the decimal, then use the Math.floor() function.

 

event.value = Math.floor(event.value);

 

  

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
December 29, 2021

Exactly what I needed. Thank you so much, Thom!