@ryniaubenpm/amet-quod-earum
Version:
Are you tired of converting environment variables to their respective types, like me? Then this package is for you! This package converts the values of environment variables to their respective types, so you don't have to worry about it anymore.
29 lines (27 loc) • 797 B
JavaScript
import BigNumber from "bignumber.js";
export const formatNumberString = ({numberString, fragtionsCount = 0, roundMode = 1, suffix = ''}: {
numberString: string,
fragtionsCount?: number
roundMode?: BigNumber.RoundingMode
suffix?: string;
}) => {
if (!numberString) return '0';
if (typeof numberString !== 'string') {
numberString = new BigNumber(numberString).toFixed();
}
const fmt = {
prefix: '',
decimalSeparator: '.',
groupSeparator: ',',
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: ' ',
fractionGroupSize: 0,
suffix: suffix,
};
BigNumber.config({ FORMAT: fmt });
if (fragtionsCount) {
return new BigNumber(numberString).toFormat(fragtionsCount, roundMode);
}
return new BigNumber(numberString).toFormat();
};