-3

I want to use JQuery to round up the total number. Since the number is a currency, I want it to round up with 2 decimal points

$('.total').text( parseFloat($('.itemOne').text()) * ($('.itemTwo').text())).toFixed(2);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="itemOne" style="display: none;">12</div>
<div class="itemTwo" style="display: none;" >0.6</div>    
Total:<div class="total"></div>

Current result: Total: 7.199999999999999

Needed result: Total: 7.20

http://jsfiddle.net/Lcr0qknx/

Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48
VM76567
  • 3
  • 1
  • Did you see that you have an error in console, right? – Calvin Nunes Jul 17 '19 at 13:33
  • 2
    Surely your research on this turned up some solutions. [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – charlietfl Jul 17 '19 at 13:34

1 Answers1

0

You can use Math.round():

var total = parseFloat($('.itemOne').text()) * parseFloat($('.itemTwo').text());
$('.total').text(Math.round(total * 100) / 100);
Thomas
  • 8,426
  • 1
  • 25
  • 49