Hi ,
I have one scenario that where
if the value is not 0 and the values should not round off and it should accept up to 9 decimals like 3.612232423.
Minimum Rate: 3.5
Maximum Rate: 4
input value is of number(dec) format i mean CDT has this data type, how can we achieve this if user enters any values apart from the scenario mentioned above should not except.
Thanks in advance.
Discussion posts and replies are publicly visible
Why not just use a!floatingPointField() to collect the user input? This will only allow a decimal value to be entered.
No, I tried with that by using floating field
Can you explain what you need that isn't accomplished by using this? It's pretty unclear what you're trying to accomplish.
ok ,Here I have sample code
a!textField( align: "RIGHT", required: ri!isActive_bool, value: rule!CR_FN_setDecimalValues( value_dec: fv!item.tariffAmountProposed_dec, decPlace_int: 9 ), validations: if( fv!item.tariffAmountProposed_dec = 0, {}, if( fv!item.tariffAmountProposed_dec >9, "Value must be less than or equal to 9", if( fv!item.tariffAmountProposed_dec < 3.5, "Value must be greater than or equal to 3.5", if( fv!item.tariffAmountProposed_dec > 4, "Value must be less than or equal to 4", "" ) ) ) ), saveInto: { fv!item.tariffAmountProposed_dec }, disabled: ri!isReadOnly_bool )
Validation provided like this where if user enter more than 9 decimals validation is not coming up and value is not rounding off,How can I achieve those above validations if user enters any other format validation should throw.
Is this what you're trying to do? This will validate that that the value must be between 3.5 and 4 and that it can have a maximum of 9 digits after the decimal point:
a!localVariables( local!decimalValue: todecimal(null), a!floatingPointField( value: local!decimalValue, saveInto: local!decimalValue, validations: { if( or( local!decimalValue > 4, local!decimalValue < 3.5 ), "Value must be between 3.5 and 4", null ), if( round(local!decimalValue, 9) <> local!decimalValue, "Value must have 9 or fewer digits after the decimal point", null ) } ) )
I'm not completely sure this line will have the intended effect, though?> round(local!decimalValue, 9) <> local!decimalValue,
Ah are you worried about zeroes after the last digit or floating point math issues (or did I make a mistake somewhere)? I didn't think adding zeros after the last digit would be relevant, but I suppose floating point issues could apply here if you have a lot of digits.
You might be right - after a little more testing it turns out my fears may have been unjustified (i was worried, for instance, that round() being called on a shorter decimal might mess with the returned value somehow).
I think it's still a little ripe for corner cases. Like this one, where it returns "false" even when we'd hope it might return "true".round(9.1111111119, 9) = 9.111111111
Ah good point - in that case it probably is best to store it as text and do something that truncates the results - maybe something like this:
a!localVariables( local!text: "3.6767676767676767676767676", local!decimal: index(split(local!text, "."), 2, ""), len(local!decimal)>9 )
yeah this works but if we convert that field to text field, The value which holds that field in database has to be change to varchar(now the field is numeric. My concern is that use can also enter other format(like special characters/8..9 smtg like this) how to handle validation for this type of format? Any suggestions?