Checking for specific digits after comma in decimal

0
I'm looking for a way to check whether a specific (range) of numbers is used after the comma/dot in a decimal. Our Weight attribute is a decimal, but users should receive a warning when they don't use round numbers. It should not be blocking though, so just removing the 2 digits after the comma won't work, unfortunately. Therefore I'm trying to come up with the correct way to check if there's a 1-9 after the comma in the on change event. 
asked
3 answers
3

Maybe a condition like this (when false, show warning):

$object/Decimalvalue != empty and $object/Decimalvalue mod 1 = 0

or

$object/Decimalvalue != empty and $object/Decimalvalue - floor($object/Decimalvalue) = 0

Or don't give users the option to do it wrong and set the decimal precision for the input widget to 0, or silently change the value to round($object/Decimalvalue).

answered
1

Hi Manon,

     As your'e mentioning if user give 1.0, 1.00 or 1 means it should be valid else if the user gives 1.01 or 1.11 means its invalid.

For this you can use below logic:

if ($Entity/DecimalValue - floor($Entity/DecimalValue)) = 0 means valid

else false

 

answered
0

Hey Manon,

You can use following regex 

isMatch($string,'^[0-9]*(\.[0]{0,2})?$')

1234.00 true

1234.01 false

1234 true

answered