Skip to main content
Commonmark migration
Source Link

#Python, 61 bytes

Python, 61 bytes

f=lambda n,i=0:"%.1f%cB"%(n," kMG"[i])*(n<1e3)or f(n/1e3,i+1)

Call like f(999). Note that 1e3 is a float, so this works with both Python 2 and Python 3.

#Python, 61 bytes

f=lambda n,i=0:"%.1f%cB"%(n," kMG"[i])*(n<1e3)or f(n/1e3,i+1)

Call like f(999). Note that 1e3 is a float, so this works with both Python 2 and Python 3.

Python, 61 bytes

f=lambda n,i=0:"%.1f%cB"%(n," kMG"[i])*(n<1e3)or f(n/1e3,i+1)

Call like f(999). Note that 1e3 is a float, so this works with both Python 2 and Python 3.

Source Link
Sp3000
  • 61.9k
  • 13
  • 115
  • 287

#Python, 61 bytes

f=lambda n,i=0:"%.1f%cB"%(n," kMG"[i])*(n<1e3)or f(n/1e3,i+1)

Call like f(999). Note that 1e3 is a float, so this works with both Python 2 and Python 3.