Copy the string data into currency field

Jyoti Tripathi
Giga Guru

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

JyotiTripathi_0-1701869337999.pngJyotiTripathi_1-1701869410599.png

 

please kindly help

 

1 ACCEPTED SOLUTION

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);

        }
    }
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

15 REPLIES 15

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);

        }
    }
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi @Jyoti Tripathi ,

Did you get chance to try this?

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@Anil Lande : Yes, but it is giving me incorrect value  for example  for 145.677, it is giving 0.67 

It is working fine for me, please share your latest script.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Ideally as per mathematical expression, if the value 123.677 it should round up to 123.68 which is correct calculations 

parseFloat(strValue).toFixed(2);
Regards,Shamma Negi