Skip to content

Instantly share code, notes, and snippets.

View TCasablancas's full-sized avatar

Thyago Casablancas TCasablancas

View GitHub Profile
@vitorfreitas
vitorfreitas / format.js
Created December 10, 2018 22:57
Formatar strings que representam dinheiro em React Native
export const formatNumber = (amount, decimalCount = 2, decimal = ",", thousands = ".") => {
try {
decimalCount = Math.abs(decimalCount);
decimalCount = isNaN(decimalCount) ? 2 : decimalCount;
const negativeSign = amount < 0 ? "-" : "";
let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(decimalCount)).toString();
let j = (i.length > 3) ? i.length % 3 : 0;