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

Truncating Decimals into Integer

New Here ,
Dec 29, 2021 Dec 29, 2021

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.

TOPICS
JavaScript
812
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
1 ACCEPTED SOLUTION
Community Expert ,
Dec 29, 2021 Dec 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

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 ,
Dec 29, 2021 Dec 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Dec 29, 2021 Dec 29, 2021
LATEST

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

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