Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Friendly Number by Moff
def friendly_number(n, decimals=0, base=1000, suffix='', powers=None):
if powers is None:
powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
pw = 0
sign = '-' if n < 0 else ''
n = abs(n)
while pw < len(powers) - 1 and n >= base:
if decimals:
n /= base
else:
n //= base
pw += 1
return '{{}}{{:.{}f}}{{}}{{}}'.format(decimals).format(sign, n, powers[pw], suffix)
Aug. 3, 2015