Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
formatting with nested curly braces solution in Clear category for Friendly Number by David_Jones
from math import log
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
powered = min(int(log(abs(number), base)), len(powers)-1) if number else 0
number /= base ** powered
if not decimals:
number = int(number)
return '{:.{}f}'.format(number, decimals) + powers[powered] + suffix
May 13, 2019
Comments: