Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
format solution in Clear category for Friendly Number by akaka
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
idx = 0
ans = float(number)
digit = '{:.' + str(decimals) + 'f}'
while idx < len(powers) - 1 and abs(ans) >= base:
ans = ans / base
idx += 1
else:
if decimals == 0: ans = int(ans)
return(digit.format(ans) + powers[idx] + suffix)
Aug. 23, 2018
Comments: