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
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);}
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
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?
Copy link to clipboard
Copied
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);}