Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;}
Copy link to clipboard
Copied
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;}
Copy link to clipboard
Copied
It worked! Thank you so much!
Copy link to clipboard
Copied
I have a field that divides a number by 100 and I only want to show two places past the decimal without rounding, would this work for that and would I need to add this to the formula that does the dividing or would this go into a format tab?
Code I was using in the calculate tab:
var grandTotal = +getField("GrandTotal").value;
if (!isNaN(grandTotal) && grandTotal !== 0) {
event.value = grandTotal / 100;
}
Code I was using in the format tab:
event.value = util.printf("%.2f", event.value);
Thank you in advance if you can help.
Copy link to clipboard
Copied
I have a field that divides a number by 100 and I only want to show two places past the decimal without rounding, would this work for that and would I need to add this to the formula that does the dividing or would this go into a format tab?
Code I was using in the calculate tab:
var grandTotal = +getField("GrandTotal").value;
if (!isNaN(grandTotal) && grandTotal !== 0) {
event.value = grandTotal / 100;
}
Code I was using in the format tab:
event.value = util.printf("%.2f", event.value);
Thank you in advance if you can help.