Method: rich.filesize.decimal
Calls: 10, Exceptions: 0, Paths: 1Back
Path 1: 10 calls (1.0)
1111 (4) 0 (2) 1 (1) 2 (1) 1000 (1) 1500000.0 (1)
1 (7) 2 (2) 0 (1)
' ' (9) '' (1)
'0 bytes' (2) '1 byte' (1) '2 bytes' (1) '1.0 kB' (1) '1.5 MB' (1) '1 kB' (1) '1.1 kB' (1) '1.11 kB' (1) '1.1kB' (1)
1def decimal(
2 size: int,
3 *,
4 precision: Optional[int] = 1,
5 separator: Optional[str] = " ",
6) -> str:
7 """Convert a filesize in to a string (powers of 1000, SI prefixes).
8
9 In this convention, ``1000 B = 1 kB``.
10
11 This is typically the format used to advertise the storage
12 capacity of USB flash drives and the like (*256 MB* meaning
13 actually a storage capacity of more than *256 000 000 B*),
14 or used by **Mac OS X** since v10.6 to report file sizes.
15
16 Arguments:
17 int (size): A file size.
18 int (precision): The number of decimal places to include (default = 1).
19 str (separator): The string to separate the value from the units (default = " ").
20
21 Returns:
22 `str`: A string containing a abbreviated file size and units.
23
24 Example:
25 >>> filesize.decimal(30000)
26 '30.0 kB'
27 >>> filesize.decimal(30000, precision=2, separator="")
28 '30.00kB'
29
30 """
31 return _to_str(
32 size,
33 ("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"),
34 1000,
35 precision=precision,
36 separator=separator,
37 )