Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using tricky form of "if" statement solution in Clear category for Friendly Number by Sebastian.M
def friendly_number(n, base=1000, decimals=0, suffix='',
powers=('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')):
pow = 0
while pow < len(powers) - 1 and abs(n) >= base:
n = n / base if decimals != 0 else n // base if n > 0 else -(abs(n) // base)
pow += 1
return "{0:.{1}f}{2}{3}".format(n, decimals, powers[pow], suffix)
Nov. 5, 2016