Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friendly Number by arek.kowalski107
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
main = float(number)
powerLength = len(powers)
i = 0
while abs(main) >= base and i < powerLength - 1:
main /= base
i += 1
if decimals == 0:
main = int(main)
else:
main = round(main, decimals)
fmt = "%."+str(decimals)+"f"+powers[i]+suffix
ret = fmt % main
return ret
Dec. 14, 2016