Skip to main content
Participant
March 8, 2022
Answered

How to set a number to only show three decimal places with no rounding

  • March 8, 2022
  • 1 reply
  • 1309 views

Hi! I am trying to create a field that only allows the following criteria:

 

1. A number from 0-100

2. Only allow for three decimal places

3. The third decimal place doesn't round if more than three decimal places are entered

 

I have tried using the Number formatting and setting the decimal place to three while setting a limit of six characters. This works for numbers 10-100, however it allows a number from 0-9 to be input with four decimal places (i.e., 1.1235). Because the decimal place is set to three, the 1.1235 will round to 1.124, which is what I don't want. Is there any way to truncate the fourth decimal place or prevent more than three from being entered for numbers 0-9?

This topic has been closed for replies.
Correct answer Nesa Nurani

Try this as validation script:

var num = event.value;
if(isNaN(num)  || (num > 100 || num < 0)){
app.alert("Please enter number between 0-100.");
event.rc = false;}
else{
var dec = num.match(/^-?\d+(?:\.\d{0,3})?/)[0];
event.value = dec;}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
March 8, 2022

Try this as validation script:

var num = event.value;
if(isNaN(num)  || (num > 100 || num < 0)){
app.alert("Please enter number between 0-100.");
event.rc = false;}
else{
var dec = num.match(/^-?\d+(?:\.\d{0,3})?/)[0];
event.value = dec;}

i1238Author
Participant
March 8, 2022

It worked! Thank you so much!