Hi All,
I need to show and store 7 digits after decimal and before decimal its 'n' number and the data type is number(decimal) how I can do that?
Thanks in advance.
Discussion posts and replies are publicly visible
Do you want to allow the user to enter any number but always have it be presented in the User Interface always with the full 7 digits after the decimal point? Examples:
Enter: 123 -> presented as 123.0000000
Enter: 12.12345678 -> presented as 12.1234568
Enter: .2 -> presented as 0.2000000
Is that the requirement?
Thanx For the reply Stewart
If user enter 12345.1234567899 then in UI it should show and store only 1234.1234567
if enter 123456.12 it will show as it is, only after 7 digits it will not show
Ok, so you need to separate in your mind how the data is held in memory (this will be using a Decimal data type) from how you want it captured/presented to the user. This code snippet might help:
a!textField( label: "My Decimal", value: fixed(ri!myDecimal,7), saveInto: { a!save( ri!myDecimal, if( fn!regexmatch( "^\d*(\.\d+)?$", save!value, "i" ), save!value, 0 ) ), } ),
The ri!myDecimal is of type Number(Decimal) but as you can see I'm using a Text Field to allow the user to enter their value.
Where the text entered conforms to the pattern of a Decimal (that's what the RegEx expression is checking) then it is presented as a Decimal with 7 digits after the decimal point (that's what the fixed() function is doing)
Because the input field is text you need to handle the fact that a user might enter non-decimal representations e.g. "ABC". That's what the second part of the if() statement is doing.
Hope this helps.