返回 DeepSeek-Reasonix
1 def humanise(n):
2 """Compact number: below 1000 the plain integer, otherwise one decimal with
3 the unit, rounded half up. 1250 -> '1.3k', 1234 -> '1.2k',
4 3_450_000 -> '3.5M'.
5 """
6 if n < 1000:
7 return str(n)
8 if n < 1000000:
9 return "%d.%dk" % (n // 1000, (n % 1000) // 100)
10 return "%d.%dM" % (n // 1000000, (n % 1000000) // 100000)
11
11 lines PYTHON