Controlling the number of decimal digits in a number item

  • Published by Viedoc System 2021-02-16
  • Print

Note! To control significant digits, use a free-text field. Number fields in Viedoc will chop the zeros preceding and succeeding a value, since 1 is treated as 1.0 and 0001. Thus, 1, 1.0, and 00001 are all technically the same "number."

Sometimes you might want to make sure that the number of entered decimal digits of a number item are neither more nor fewer than a specified number. To do so, add code to the validation of a text item, in the Data checks section.

The following example code makes sure that the exact number of decimal digits in a number item is 1:

var re = /((\d+)(\.\d{1}))$/;

return re.test(FieldID)==true;

where FieldID is the ID of the number item and 1 is the number of decimal digits.

For more information on how to use JavaScript in Viedoc see Using JavaScript in Viedoc.