Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
friendly solution for friendly number solution in Clear category for Friendly Number by Tinus_Trotyl
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."""
pf_index = 0
while abs(number) >= base and pf_index < len(powers)-1 :
number, pf_index = number/base if number%base else number//base, pf_index + 1
whole = str(int(number))
dot = "." if decimals else ""
fraction = str(round((abs(number)%1 + 1) * 10**decimals))[1:] if decimals else ""
prefix = powers[pf_index]
return whole + dot + fraction + prefix + suffix
Oct. 27, 2017