Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Friendly Number by McRawicz
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
znak=""
if number<0:
number*=-1
znak+="-"
x=0
while number>=base**x:
x+=1
if x > 0:
x-=1
if x>=len(powers):
x=len(powers)-1
if decimals==0:
wartosc=number//base**x
str_wartosc=str(wartosc)
else:
wartosc=round(number/base**x,decimals)
str_wartosc=str(wartosc)
i=-1
while str_wartosc[i]!='.':
i-=1
while abs(i)<=decimals:
i-=1
str_wartosc+='0'
return znak+str_wartosc+powers[x]+suffix
Nov. 4, 2016