How to round percentage?

Asked

Viewed 834 times

-1

I would need the function below in .asp. I have no notion of language, someone can help?

Fiz em Javascript, segue:

function limparClasse(classe) {
    var elementos = document.querySelectorAll('.' + classe);
    for (var i = 0; i < elementos.length; i++) 
        elementos[i].innerHTML = elementos[i].innerHTML.replace(/,.*%/, "%");
}


limparClasse('vtex-cpShow');
<span class="desconto-de vtex-cpSave  vtex-cpShow ">36,00 % OFF</span>

  • in Asp is used the control $product.Listpriceminusbestpriceinpercent OFF

  • Are you using a Textbox? How are you assigning this information?

  • The value comes 30.0 % OFF is generated by the system

  • Which system? Are you using any framework? I’m trying to understand the context. Can you provide more details? Your question is too vague.

  • Is it ASP or ASP.NET? The problem is ASP-related or is it just Javascript?

  • It is a cms(vtex platform), the $product.Listpriceminusbestpriceinpercent would be a control. This control generates the percentage within the <span> with two decimal places, it would need to round.

  • bigown would be ASP.NET. The problem is actually with javascript, I’m using an Infinite scroll(plugin) of products but I can’t include the function I mentioned when new products are loaded. That’s why I’m trying to round off directly from Asp.net, if possible.

  • Where does the information come from? Complete code is required, or if only the way to replace one string with another was provided, it would help?

  • Guys, thanks for the help, I was able to solve by incredible as it may seem by CSS(rs) width and overflow:Hidden.

  • 3

    @lucasinverso actually like this you solved on your screen and in your browser. this solution of hiding piece of string will give problem, depending on the size of the digits, the browser involved and a number of other factors. Tip: click "edit" below the question, explain the result you want, with examples (not just code), so we can vote to reopen the question, and someone can give a real answer.

Show 5 more comments

1 answer

2

Normally calculate the percentage in ASP and use the function Round round.

Example 1

<%

    response.write(Round(24.13278) & "<br />")
    response.write(Round(24.75122))

%>

Upshot:

24
25

Example 2

Rounding, keeping 2 decimal places:

<%

    response.write(Round(24.13278,2))

%>

Upshot:

24.13

Vbscript Round Function

Browser other questions tagged

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