Round values 10.34 for whole numbers... Ex: 10 - Does not work with infinite scroll

Asked

Viewed 28 times

1

I’m here cracking my head to solve a difficulty I’m facing, so I’ve come to ask for your help.

My platform has that problem of presenting broken numbers (ex: 10.42% OFF) in the % of product discount.

Searching the internet, I found a JS function that seemed to have solved the case, but partially solved, because when the page loads more products (next page), the js does not work and the numbers remain decimal after the comma.

I believe that this has some relation with the issue of the site have infinite scroll... as I do not understand of JS, I can not find a solution.

I wonder if you can help me?!

function limparClasse(classe) {
var elementos = document.querySelectorAll('.' + classe);
for (var i = 0; i < elementos.length; i++) {
    var elemento = elementos[i];
    var string = elemento.innerHTML;
    var novaString = string.split('%');
    var arredondamento = parseInt(novaString[0], 10);
    var resultado = arredondamento + '%' + novaString[1];
    elemento.innerHTML = resultado;
}

}

cleanClasse('vtex-cpShow');

  • William, this topic you sent has nothing to do with my question

  • What is missing in your question are practical examples and more explanations. There falls in the generic, as marked as duplicate.

  • Easier to use Math.round(). Ai already round and should not give more problems.

  • @Antoniuslourençokasbergen good afternoon... can show me an example in practice with the Math.round ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.