This topic is locked

Add Event JavaScript Number format

1/7/2023 5:40:50 PM
PHPRunner General questions
E
excalibur author

I have a Javascript Onload Event that calcualtes field values on the fly and can fix the decimal using the toFixed () code suggested in this forum and repeated below. However, I cannot find a way to show the number as a currency or en-US number format (##,###.##). Any suggestions?

function func() {

var va1 = Number(ctrlBodyTechRetail.getValue()) - Number(ctrlBodyTechCost.getValue());
ctrlBodyTechGP.setValue(val1.toFixed(1));
var val2 = (Number(ctrlBodyTechRetail.getValue()) - Number(ctrlBodyTechCost.getValue())) / Number(ctrlBodyTechRetail.getValue ())*100;
ctrlBodyTechGPP.setValue(val2.toFixed(1));

};

E
excalibur author 1/8/2023

Update - I left out that we can format using Javascript toLocaleStgring() function, however, we can only store the results as a Varchar and we prefer an INT or decimal.

fhumanes 1/9/2023

Hello,

In order not to have to insert the values into a varchar field, you must enter code in the "Before Add" and "Before Updated" events, to eliminate the score symbols of the thousands to adapt the decimal score symbol.

Regards,
fernando