@livelike/react-native
Version:
LiveLike React Native package
21 lines (20 loc) • 711 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.abbrevNum = abbrevNum;
exports.roundTo = roundTo;
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];
}
function roundTo(num, decimalPlaces) {
const roundToFactor = Math.pow(10, decimalPlaces);
return Math.round(num * roundToFactor) / roundToFactor;
}
//# sourceMappingURL=number.js.map