How to enforce decimals, even if the decimal is zero?

0
Problem/Goal: I want to enforce the system to handle, at least for one specific entity, that the decimal value will always have a decimal. In context: grades. I've set the text box decimal precision to '1' and tested a custom RegEx at https://regex101.com/r/2HYdJp/2/tests which is accepting 7.0, 7.1 and rejecting '7', but Mendix is still rejecting '7.0'. I assume Mendix is removing the '0' decimal and change the input to '7'. Context: To create consistency in both writing and viewing these numbers, I want the numbers always consists of one single decimal. So in both a text field and a list, it will show '7.0', instead of '7'. My feeling that Mendix is removing the zero is increased, as the RegEx (as shown below) will only accept '0' and disallow '0.0', but if I enter '0.0' in the field, it will accept my input.  Is it possible to enforce the decimal, even with zeros?   For the record: This is my RegEx I use to validate the value.. /^0$|^[1-9]{1}\.[0-9]{1}$|^10\.0$/g Explanation; grades: A zero for 'unassigned grade', and 1.0 - 9.9 + 10.0 (separated, as 10.1 would otherwise be accepted as well), for a assigned grade. (I.e. accept 0, 1.0, 7.3, 10.0, reject '0.0', '1', '10.3')    I already thought of converting it to a string, but you cannot use 'AggregateList: Average' on a string..  
asked
3 answers
1

You could try setting the decimal precision to 1 character in a form or grid, see for example: https://docs.mendix.com/refguide/text-box

 

answered
0

Hi Sander,

In what situation do you encounter difficulties? For entering, you can set decimal precision of your Decimal attribute to 1, so any number entered will show 1 decimal.

Same goes for displaying, but in the entry form and overview.

answered
0

As both Wieke and Maarten have said, it sounds like you need to set the Decimal precision to 1.

If you want to restrict the values to between 0 and 10.0, you can also as a Custom validation and use the Expression

$value >= 0 and $value <= 10
 

That will throw a validation error if anything other than a decimal between 0 and 10.0 is entered.

answered