MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / format_sizeof

Method format_sizeof

pager_lib/tqdm/std.py:370–397  ·  view source on GitHub ↗

Formats a number (greater than unity) with SI Order of Magnitude prefixes. Parameters ---------- num : float Number ( >= 1) to format. suffix : str, optional Post-postfix [default: '']. divisor : float, optional

(num, suffix='', divisor=1000)

Source from the content-addressed store, hash-verified

368
369 @staticmethod
370 def format_sizeof(num, suffix='', divisor=1000):
371 """
372 Formats a number (greater than unity) with SI Order of Magnitude
373 prefixes.
374
375 Parameters
376 ----------
377 num : float
378 Number ( >= 1) to format.
379 suffix : str, optional
380 Post-postfix [default: ''].
381 divisor : float, optional
382 Divisor between prefixes [default: 1000].
383
384 Returns
385 -------
386 out : str
387 Number with Order of Magnitude SI unit postfix.
388 """
389 for unit in ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z']:
390 if abs(num) < 999.5:
391 if abs(num) < 99.95:
392 if abs(num) < 9.995:
393 return f'{num:1.2f}{unit}{suffix}'
394 return f'{num:2.1f}{unit}{suffix}'
395 return f'{num:3.0f}{unit}{suffix}'
396 num /= divisor
397 return f'{num:3.1f}Y{suffix}'
398
399 @staticmethod
400 def format_interval(t):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected