Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  115] [ 1]  / answers: 1 / hits: 5815  / 11 Years ago, tue, december 10, 2013, 12:00:00

I made a JQuery function to calculate the amount including the tax. When I want to set a amount with cents I need to use a dot. It will be like 125.25 euro's. I would like to know how to calculate the amount including tax by using a comma.



here is my code:



    if($(#tax).val() == verlegd) { var tax= 0;  }
else
{
var tax= parseInt($(#tax).val());
}

var taxCalc = parseInt(100+tax);
var amount= parseFloat($(#amount).val());

var amountinc = Math.round(((amount* taxCalc) / 100)*100)/100;
if(!isNaN(amount))
{
$(#amountinc).val(amountinc);
}
else
{
$(#amountinc).val(unvalid number);
}
}

$(#amount).keyup(function(){ updateTotalExc(); });
$(#tax).change( function(){ updateTotalExc(); });

More From » jquery

 Answers
13

If I've understood the question correctly, you can use replace to change all commas to dots within the #amount value.



var amount = $(#amount).val().replace(',', '.');

[#49683] Monday, December 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
randall

Total Points: 492
Total Questions: 99
Total Answers: 103

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
randall questions
Wed, Mar 16, 22, 00:00, 2 Years ago
Tue, Nov 10, 20, 00:00, 4 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
;