JQuery HTML Currency Mask (non-input)

0

Hello. I'm behind a currency mask made in jquery, but applied directly to an html span tag, with a specific class. What else I have found in my searches are the input masks for forms, which is not the case. I ended up getting a bit confused, because my knowledge of JS is not much.

So by exemplifying an HTML

    <li>
    <span class="mylabel">Valor do Aluguel:</span>
    <span class="myvalue">25000000</span>
    </li>

In the example the script would transform this type of result to 25000000 in - > 25.0000,00 That is, forcing the default currency format from here in a chosen field.

Logically following the same pattern for other types of values:
60050 - > 600,50
110000 - > 1,100,00
250035085 - > 2,500,350.85
etc.

Possible? How would you do?

Thanks in advance.

    
asked by anonymous 09.10.2018 / 04:30

1 answer

1

You can do this through toLocaleString

$(".myvalue").text(parseInt($(".myvalue").text()).toLocaleString('pt-br', {
  style: 'currency',
  currency: 'BRL',
 
}));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><li><spanclass="mylabel">Valor do Aluguel:</span>
  <span class="myvalue">25000000</span>
</li>
    
09.10.2018 / 14:10