I have the following function which totals up three field values:
function calculatePublicTransportTotalClaim(){
var Bus_Weekly_Claim = formatNum( $('#Bus_Weekly_Claim').val() );
var Train_Weekly_Claim = formatNum( $('#Train_Weekly_Claim').val() );
var Tram_Weekly_Claim = formatNum( $('#Tram_Weekly_Claim').val() );
var Total = Bus_Weekly_Claim + Train_Weekly_Claim + Tram_Weekly_Claim;
console.log( Total )
$('#PublicTransport_Weekly_Claim').val( Total );
}
The inputs have a default value of 0.00
And they have their values converted to ints using formatNum which looks like:
function formatNum(n) {
var round = Math.round;
n = round(n);
return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
}
However when I call the function calculatePublicTransportTotalClaim, the returned Total is: 0.000.000.00
What have I done wrong? As the values should now be numbers, but instead they seem to be acting like strings when I'm adding them together.