Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple & compact solution in Clear category for [old] Friendly Number by MaxGraey
function friendlyNumber(number, {base=1000, decimals=0, suffix='', powers=' k M G T P E Z Y'.split(' ')} = {}) {
var val = number, exp = 0
number = Math.abs(number)
while (number >= base) {
number /= base, exp++
}
exp = Math.min(powers.length-1, exp)
val /= base ** exp
val = decimals ? val.toFixed(decimals) : val | 0
return `${val}${powers[exp]}${suffix}`
}
May 20, 2019
Comments: