Last active
August 2, 2023 16:21
-
-
Save davidalves1/883e898fcd8d91a5f946965f137ca457 to your computer and use it in GitHub Desktop.
Formatando valores para string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const num = 15236.639; | |
console.log(num.toLoacaleString('pt-BR')); | |
// "15.236,639" | |
console.log(new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(num)); | |
// "R$15.236,64" | |
const now = new Date(); | |
console.log(now.toLocaleString('pt-BR')); | |
// Function to generate a radom string with defined length | |
function randomString(length) { | |
let result = ''; | |
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
for (let i = length; i > 0; --i) | |
result += chars[Math.round(Math.random() * (chars.length - 1))]; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment