Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Decimal Field Pattern limit to 2 decimals only

Avatar

Former Community Member
Hi,



I am want to limit a numeric field to 4 leading digits and only 2 trailing digits, example 1,234.59. I have set this pattern up in the Display pattern: num{z,zz9.99}|num{z,zz9.zz}|num.currency{}.



The problem is if the user enters less than 4 leading digits, s/he can enter more than 2 decimal places. The the field rounds off the value, which I do not want. Example: enters 123.456 = displays 123.46 rather than 123.45.



Any suggestions?



Thanks,



Pam
1 Reply

Avatar

Level 5
Pam:

Try setting the field to be Numeric instead of Decimal, and place this in the exit event.

Uncomment the alerts to see the individual results



// multiply by 100 to shift without rounding

temp1 = this.rawValue * 100;

//app.alert("temp1: " + temp1);

// convert to int. to drop remaining decimals

temp2 = parseInt(temp1);

//app.alert("temp2: " + temp2);

// divide by 100 to shift back 2 places

temp3 = temp2 / 100;

//app.alert("temp3: " + temp3);

// return data to field

this.rawValue = temp3;