function NumbFormat(options) {
let number = Math.abs(Number(options.number));
// Nine zeros for Billions
if (Number(number) >= 1.0e+9) {
return (number / 1.0e+9).toFixed(options.billion.decimal) + ` ${options.billion.unit}`;
}
// Six zeros for Millions
if (Number(number) >= 1.0e+6) {
return (number / 1.0e+6).toFixed(options.million.decimal) + ` ${options.million.unit}`;
}
// Thrhee zeros for Thousands
if (Number(number) >= 1.0e+3) {
return (number / 1.0e+3).toFixed(options.thousand.decimal) + ` ${options.thousand.unit}`;
}
return number;
}
console.log(NumbFormat({
'number': 100000000,
'billion': {
'decimal': 1,
'unit': 'B',
},
'million': {
'decimal': 1,
'unit': 'M',
},
'thousand': {
'decimal': 1,
'unit': 'K',
},
}));
console.log(NumbFormat({
'number': 100000000,
'billion': {
'decimal': 1,
'unit': 'B',
},
'million': {
'decimal': 1,
'unit': 'Million',
},
'thousand': {
'decimal': 1,
'unit': 'K',
},
}));
console.log(NumbFormat({
'number': 100000000,
'billion': {
'decimal': 1,
'unit': 'B',
},
'million': {
'decimal': 0,
'unit': 'Million',
},
'thousand': {
'decimal': 1,
'unit': 'K',
},
}));
console.log(NumbFormat({
'number': 100000000,
'billion': {
'decimal': 1,
'unit': 'B',
},
'million': {
'decimal': 0,
'unit': 'M',
},
'thousand': {
'decimal': 1,
'unit': 'K',
},
}));