-3

我想使用 JQuery 来对总数进行四舍五入。由于数字是货币,我希望它以 2 个小数点四舍五入

$('.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>

当前结果:总计:7.199999999999999

需要的结果:总计:7.20

http://jsfiddle.net/Lcr0qknx/

4

1 回答 1

0

您可以使用Math.round()

var total = parseFloat($('.itemOne').text()) * parseFloat($('.itemTwo').text());
$('.total').text(Math.round(total * 100) / 100);
于 2019-07-17T13:33:39.330 回答