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

Prashant Ahire
Kilo Sage

Hello @Jyoti Tripathi 

The above code is tested in my Personal Instance and got the expected output- 

(function executeRule(current, previous /*null when async*/ ) {

    var payRate = current.u_pay_rate_amount;
    payRate = parseFloat(payRate).toFixed(2);
    current.u_wage_rate = "USD;" + payRate;
    current.update();

})(current, previous);
 
PrashantAhire_0-1701932261993.png

Please check and Mark Helpful and Correct if it really helps you.
Regards,
Prashant Ahire

@Prashant Ahire : But the amount got round off from 88 to 89

Prashant Ahire
Kilo Sage

@Jyoti Tripathi 
That is correct according to the mathematics - 

The number is rounded up if the tenth digit equals or more than five. However, the number is rounded down if it is less than 5. If the digit on the tenth decimal value happens to be more than 5, then one is added to the whole number left to the decimal point

 

for your reference- 

https://www.splashlearn.com/math-vocabulary/decimals/rounding-decimals#:~:text=Rounding%20is%20a%20p....

https://www.turito.com/learn/math/rounding-decimals

 

Please check and Mark Helpful and Correct if it really helps you.
Regards,
Prashant Ahire

 

Hello @Jyoti Tripathi 

Did this helped you?

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful.
Thanks
 

@Prashant Ahire : I got your point but this is about payroll, it should not get round off.