UNPKG

@livelike/react-native

Version:

LiveLike React Native package

14 lines 587 B
export function abbrevNum(num) { const unitSymbols = ['', 'k', 'M']; const tier = Math.log10(num) / 3 | 0; if (tier == 0) return num; const scaled = num / Math.pow(10, tier * 3); // Check if number is whole or above 100k so '.0' doesn't get added. const wholeOrThreeDigit = scaled % 1 === 0 || scaled >= 10 ? 0 : 1; return scaled.toFixed(wholeOrThreeDigit) + unitSymbols[tier]; } export function roundTo(num, decimalPlaces) { const roundToFactor = Math.pow(10, decimalPlaces); return Math.round(num * roundToFactor) / roundToFactor; } //# sourceMappingURL=number.js.map