Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Decimal FTW solution in Clear category for Friendly Number by veky
def friendly_number(number, base=1000, decimals=0, suffix='',
powers=('',)+tuple('kMGTPEZY')):
"""Format a number as friendly text, using common suffixes."""
import decimal
number = decimal.Decimal(number)
for pw in powers:
if abs(number) < base: break
number /= base
else: number *= base
val = "{:.{}f}".format(number, decimals) if decimals else str(int(number))
return val + pw + suffix
March 29, 2014
Comments: