Copy link to clipboard
Copied
I have a field that a person enters a value into. The value has to be entered as a value of 0.5 or 0. For example:
12.00
12.50
13.00
Those values are acceptable. A value of 12.25 is not acceptable. Is there a way to basically not except a value that does not end with a .00 or a 0.50 and just leave the field blank if the operators enters something other then this?
Copy link to clipboard
Copied
Yes. Use this code as the field's custom validation script:
if (event.value) event.rc = (Number(event.value)%0.5==0);
Copy link to clipboard
Copied
I am wanting the code to automatically round up to the nearest 0.5
So if the person enters 34.75 then it will round the value up to the nearest 0.5 which would be 35.00
If the person enter 34.25 then it would round up to 35.50
Copy link to clipboard
Copied
This is a purely mathematical task. I've written some sample code that demonstrates how to do it:
var a = 34.25;
var round_a = Math.floor(a);
if (a!=round_a) {
if ((a-round_a)<=0.5)
a = round_a+0.5;
else a = round_a+1;
}
console.println(a);