Reg - toLocaleString()

Jai2021
Tera Contributor

Hi All,
I'm using the below script to make the field to display a number as currency of USD and AUD .

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var num = new Number(g_form.getValue('<your_field>')),
        
        result = num.toLocaleString("undefined", {
            style: "currency",
            currency: "USD"
        });
    g_form.setValue(  result);
}

}


But it is throwing NaN error. Can anyone help me out this.

 

If the field is filled as '9807687'  then it should display as '$9807687 USD'

1 REPLY 1

Dibyaratnam
Tera Sage

Use the code below @Jai2021 

var num = new Number(g_form.getValue('fieldName'));
	
	var result = num.toLocaleString("en-US", {
        style: "currency",
        currency: "USD"
    });
	g_form.setValue('field_name',result);

Please mark as correct if it helps.