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()))); 

example fiddle

also note can provide function html() tidy code little:

$(this).html(function(i, html) {     return math.ceil(parsefloat(html))); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -