MCPcopy Index your code
hub / github.com/MatrixTM/MHDDoS / humanbytes

Method humanbytes

start.py:241–252  ·  view source on GitHub ↗
(i: int, binary: bool = False, precision: int = 2)

Source from the content-addressed store, hash-verified

239
240 @staticmethod
241 def humanbytes(i: int, binary: bool = False, precision: int = 2):
242 MULTIPLES = [
243 "B", "k{}B", "M{}B", "G{}B", "T{}B", "P{}B", "E{}B", "Z{}B", "Y{}B"
244 ]
245 if i > 0:
246 base = 1024 if binary else 1000
247 multiple = trunc(log2(i) / log2(base))
248 value = i / pow(base, multiple)
249 suffix = MULTIPLES[multiple].format("i" if binary else "")
250 return f"{value:.{precision}f} {suffix}"
251 else:
252 return "-- B"
253
254 @staticmethod
255 def humanformat(num: int, precision: int = 2):

Callers 2

runConsoleMethod · 0.80
start.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected