Skip to content

Instantly share code, notes, and snippets.

@davidalves1
Last active August 2, 2023 16:21
Show Gist options
  • Save davidalves1/883e898fcd8d91a5f946965f137ca457 to your computer and use it in GitHub Desktop.
Save davidalves1/883e898fcd8d91a5f946965f137ca457 to your computer and use it in GitHub Desktop.
Formatando valores para string
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