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

I am trying to format a number to a maximum of 3 digits after the decimal point.

Explorer ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

I have a text field on a form that will contain a number.

for example: 4.25 or 3.375 or 5.125.

 

I am trying to format the number to a maximum of 3 digits after the decimal point but leave off the trailing zeros if any are present.

so 4.250 will look like 4.25, but 3.125 will look like 3.125

TOPICS
How to , PDF forms

Views

266

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 , Sep 01, 2022 Sep 01, 2022

Try this:

if(event.value){
var int = Number(event.value) % 1;
if(int !== 0)
event.value = parseFloat(event.value);
else
event.value = util.printf("%.1f", event.value);}

Votes

Translate

Translate
Community Expert ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

As validation script of that field, you can use this:

if(event.value)event.value = parseFloat(event.value);

Just keep in mind if you enter 04 it will remove 0 or if you enter 4.0 it will be 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
Explorer ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

I was just trying to edit my post to further explain before you posted.

So up to three digits but without trailing zeros for all numbers except whole numbers which should have 1 trailing zero.

If the number is a whole number I wanted it to be 4.0 but not 4.000

if I put in 2.25 I want it to show 2.25 and not 2.250

 

Let me break it down further

I would like the numbers to be in 1/8 decimal formats.

2.0

2.125

2.25

2.375

2.5

2.625

2.75

2.875

3.0

3.125

etc...

So up to three digits but without trailing zeros for all numbers except whole numbers which should have 1 trailing zero.

 

Is this even posible?

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 ,
Sep 01, 2022 Sep 01, 2022

Copy link to clipboard

Copied

LATEST

Try this:

if(event.value){
var int = Number(event.value) % 1;
if(int !== 0)
event.value = parseFloat(event.value);
else
event.value = util.printf("%.1f", event.value);}

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