Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Friendly Number by UFO665
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
sMinus = ""
if number < 0:
sMinus = "-"
number = abs(number)
lstPowers = [powers[0]] + [s for i, s in enumerate(powers[1:], 1) if number >= base ** i]
if len(lstPowers) > 1:
number /= float(base ** (len(lstPowers) - 1))
if decimals == 0:
number = int(number)
sFormat = "{:.%if}" % decimals
return "{}{}{}{}".format(sMinus, sFormat.format(number), lstPowers[-1], suffix)
Jan. 14, 2016