Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. var formato = { minimumFractionDigits: 2 , style: 'currency', currency: 'BRL' }
  2. $("#totalEntrada").append($entrada.toLocaleString('pt-BR', formato));
  3. $("#totalSaida").append($saida.toLocaleString('pt-BR', formato));
  4. $("#totalGeral").append($total.toLocaleString('pt-BR', formato));
  5.  
  6. toLocaleString
  7.  
  8. var numero = 1.6;
  9. var dinheiro = numero.toLocaleString("pt-BR", { minimumFractionDigits: 2 , style: 'currency', currency: 'BRL' });
  10.  
  11. function toLocaleStringSupportsLocales() {
  12. var number = 0;
  13. try {
  14. number.toLocaleString('i');
  15. } catch (e) {
  16. return eā€‹.name === 'RangeError';
  17. }
  18. return false;
  19. }
  20.  
  21. if(!toLocaleStringSupportsLocales()){
  22. Number.prototype.toLocaleString = function(lingua, opcoes) {
  23. var numero = this.toFixed(2).replace(".", ",");
  24. if(!opcoes)
  25. return numero;
  26.  
  27. if(opcoes.style == "currency")
  28. return "R$ " + numero;
  29. }
  30. }
  31.  
  32. $("#totalEntrada").append("R$ " + $entrada);
  33. $("#totalSaida").append("R$ " + $saida)
  34. $("#totalGeral").append("R$ " + $total);
  35.  
  36. $("#totalEntrada").append("R$ " + Number($entrada).toFixed(2));
  37. $("#totalSaida").append("R$ " + Number($saida).toFixed(2));
  38. $("#totalGeral").append("R$ " + Number($total).toFixed(2));
  39.  
  40. const centsToMoney = cents => 'R$' + (cents / 100).toFixed(2).replace('.', ',').split('').reverse().map((v, i) => i > 5 && (i + 6) % 3 === 0 ? `${v}.` : v).reverse().join('')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement