Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Loopless(cleaner) solution in Speedy category for Friendly Number by JumpCutter
from math import log
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
try:
powered = min(int(log(abs(number), base)), len(powers) - 1)
number /= (base**powered)
if decimals == 0: number = int(number)
except ValueError: powered = 0
return "{:.{}f}".format(number, decimals) + powers[powered] + suffix
May 12, 2014
Comments: