Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friendly Number by Ardillo95
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
p_index = 0
# Base filter
while abs(number / base) >= 1 and p_index < len(powers) - 1:
number /= base
p_index += 1
if len(str(number)) > 10 and not decimals:
number = round(number)
# Decimals filter
if decimals == 0:
number = int(number)
else:
number = format(round(number, decimals), '.' + str(decimals) + 'f')
return str(number) + powers[p_index] + suffix
Sept. 29, 2016