javascript - Round up number with decimals -
i have following output numbers prices of products:
<span class="amount">77.08</span> <span class="amount">18.18</span> <span class="amount">20.25</span> i want round them no matter price is, result in case be:
<span class="amount">78</span> <span class="amount">19</span> <span class="amount">21</span> i tried code removes whole number:
jquery('.amount').each(function () { jquery(this).html(math.round(parsefloat(jquery(this).html()))); }); any idea problem?
use math.ceil() instead of math.round():
jquery(this).html(math.ceil(parsefloat(jquery(this).html()))); also note can provide function html() tidy code little:
$(this).html(function(i, html) { return math.ceil(parsefloat(html))); });
Comments
Post a Comment