How to Limit the Number of decimal places to "two" for Price field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 12:44 AM
Hi ,
I am trying to limit the number of decimal places to "two" for price field by using "Scale" attribute to the field.
In the Dictionary configuration, I want to restrict the user should not enter more than 2 decimal places.
The decimal places are a combination of ‘Max length’ and the ‘scale’ attribute.
For the field, the scale= 2 and Modified the Maximum length as "22". (As the maximum length is 20 by default + scale)
Found 1 KB Article, Number of decimal places always rounds to 2 even when 'scale' is attribute is set - Known Error (ser...
Is any way to limit the 2 decimal places.
Thanks in Advance,
Bhavani Yavvari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 02:06 AM
Hi @Bhavani Yavvar2 ,
Scale attribute works only for decimal type field.Since you are using price type field, try to do it with a client script. Please find the below onchange client script which onruns onchange of the price type field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var sp=newValue.split(';'); //since you will be getting value which includes currency name as well for example(US;8.9)
var ps=sp[1].toString();
ps=ps.split('.');
var ps2=ps[1];
if(ps2.length>2){
var x =Number(sp[1]);
var round=Math.round(x*100)/100;
alert(round);
g_form.setValue('u_test',sp[0]+';'+round);
}
}
if it helps.Mark helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2022 05:45 AM
var num = 5.56789;
var n = num.toFixed(2);
Thanks
dgarad