Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Friendly Number by TovarischZhukov
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
i=0
for i in range(len(powers)):
val = number / float(base**i)
if abs(val) < base:
break
pow_suf=powers[i]
if decimals == 0 :
val = str(val)
pos = val.find(".")
if pos != -1:
val = val[:pos]
else:
val = str(round(val,decimals))
val+=(decimals-len(val[val.find(".")+1:]))*"0"
return val+pow_suf+suffix
Dec. 15, 2015