- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:19 AM - edited 12-06-2023 05:34 AM
Hi All, I have a requirement to copy the pay rate(string field) from caller field to wage field(currency field) and it should be truncated to two decimal places.
Example- if user's pay rate is 56.8867 then wage field should populate as $56.88
please kindly help
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:53 PM
Hi,
Try below:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue === '') {
g_form.setValue('dollar_amount', 'USD;0.00');
return;
}
var grievant = g_form.getReference('employee_id', callBack);
function callback(grievant) {
var payRate = parseFloat(grievant.u_pay_rate_amount);
g_form.setValue('dollar_amount', 'USD;'+currValue);
var currArr = payRate.split('.');
var decPart = currArr[1];
if (decPart.length > 2) {
var x = Number(grievant.u_pay_rate_amount);
var currValue = "USD;" + Math.round(x * 100) / 100;
g_form.setValue('dollar_amount', currValue);
}
}
}
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:33 AM
Hi,
If you are using server script then use :
var strValue = 56.8867;
var currValue = "USD;"+parseFloat(strValue).toFixed(2);
grObj.field_name.setDisplayValue(currValue); //use current or grObject
If it is client script then use:
var strValue = 56.8867;
var currValue = "USD;"+parseFloat(strValue).toFixed(2);
g_form.setValue('field_name' , currValue);
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 05:43 AM
@Anil Lande : Thanks Anil, the code worked but after decimal it is getting round off if its more than 2 decimal.
can we copy the exact same data.
if it is 145.677, it should be 145.67 not 145.68

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 06:08 AM
Then you need to take a long way:
var strValue = "123.4567";
currArr=strValue.split('.');
var decPart=currArr[1];
var currValue = "USD;"+parseFloat(strValue);
if(decPart.length>2){
var x =Number(strValue);
currValue="USD;"+Math.round(x*100)/100;
}
gr.fieldName.setDisplayValue(currValue);
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:34 PM
@Anil Lande : I tried but it is not working, could you please what is the issue with code
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue === ''){
g_form.setValue('dollar_amount', '0.00');
return;
}
var grievant = g_form.getReference('employee_id', callBack);
}
var payRate = parseFloat(grievant.u_pay_rate_amount);
var currArr=payRate.split('.');
var decPart=currArr[1];
if(decPart.length>2){
var x =Number(grievant.u_pay_rate_amount);
var currValue="USD;"+Math.round(x*100)/100;
g_form.setValue('dollar_amount', currValue);
}