Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Format evȺil math solution in Creative category for Friendly Number by V.Shkaberda
import math
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']):
"""
Format a number as friendly text, using common suffixes.
"""
return '{:.0f}{:0<{dec}}{}{}'.format(*eval(
"math.copysign(abs({n}) // {b} ** {i}, {n}),\
{d} and str(round(abs({n}) % {b} ** {i} / {b} ** {i}, {d}))[1:] or '',\
{p}[{i}],\
{s!r}"
.format(n=number, b=base, d=decimals, s=suffix, p=powers, i=min(math.floor(math.log(abs(number or 1), base)), len(powers)-1))),
dec=decimals and decimals+1)
June 5, 2016
Comments: