-1

Hello guys I have a question about how to calculate the tax in jquery or in javascript? I have the following problem the user can select the tax it consists of 0%,6% and 21% I got 2000.12 in stead of 2.12 how can i fix this can anyone help me please????


This is my html code for the select what I am using

<select id="Btw">
       <option value="0">0%</option>
       <option value="6">6%</option>
       <option value="21">21%</option>
</select>

Javascript

 var subtotal = 0;
  var NewBtw = 0;
  var Totaal = 0;
  $('.price').each(function(i){
    price = $(this).html().replace("&euro;","");
    if (!isNaN(price)) subtotal += Number(price);
  });

 subtotal = roundNumber(subtotal,2);
 NewBtw = roundNumber(NewBtw,2);
 Totaal = roundNumber(Totaal,2);




 var percentage = parseInt($("#Btw option:selected" ).val());
 NewBtw = (subtotal / 100) * percentage;
 Totaal = parseFloat((subtotal + NewBtw));

$('#subtotal').html(""+subtotal);
$('#BTW').html(""+NewBtw);    
$('#total').html(""+Totaal);  

Full code in this fiddle

Liam
  • 27,717
  • 28
  • 128
  • 190
murtaza
  • 29
  • 4
  • 1
    Can you add code or yours detailed approach? it will help to understand more – Roli Agrawal Mar 24 '15 at 09:03
  • var percentage = parseInt($("#Btw option:selected" ).val()); NewBtw = (subtotal / 100) * percentage; Totaal = (subtotal + NewBtw); – murtaza Mar 24 '15 at 09:10
  • murtaza, please post the current relevant HTML code. We have no idea of how your – briosheje Mar 24 '15 at 09:25
  • You haven't shown the HTML that calculates subtotal, i.e. all the .price elements. **Again** without all the information no one can answer this! – Liam Mar 24 '15 at 10:08
  • There's also a mysterious method called roundNumber that's missing. Why don't you create a https://jsfiddle.net/ for this? I also think you should be able to figure this out yourself if you simply [debug your javascript code](http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code) – Liam Mar 24 '15 at 10:10
  • 1
    I have paste the code in jsfiddle.net https://jsfiddle.net/7L4jvage/ – murtaza Mar 24 '15 at 10:36

1 Answers1

-3
<select id="Btw">
 <option value="0">0%</option>
 <option value="6">6%</option>
 <option value="21">21%</option>
</select>

This is my html code for the select what I am using

 var subtotal = 0;
  var NewBtw = 0;
  var Totaal = 0;
  $('.price').each(function(i){
    price = $(this).html().replace("&euro;","");
    if (!isNaN(price)) subtotal += Number(price);
  });

 subtotal = roundNumber(subtotal,2);
 NewBtw = roundNumber(NewBtw,2);
 Totaal = roundNumber(Totaal,2);

 var percentage = parseInt($("#Btw option:selected" ).val());
 NewBtw = (subtotal / 100) * percentage;
 Totaal = parseFloat((subtotal + NewBtw));

$('#subtotal').html(""+subtotal);
$('#BTW').html(""+NewBtw);    
$('#total').html(""+Totaal);  
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
murtaza
  • 29
  • 4
  • 1
    this sin't an answer to the question. I'm guessing you wanted to edit your question, so I've added the details for you and flagged this for moderator attention. It would be better if you delete this answer though. Answers should **only** be used to provide answers! not extra details for the question – Liam Mar 24 '15 at 09:41
  • Owh oke thanks for the information I'm new on this forum but can anyone help me? – murtaza Mar 24 '15 at 09:57