openavmkit.utilities.format
dig2_fancy_format
dig2_fancy_format(num)
Fancy-formats a number, and if the absolute value of the number is less than 100, shows it with two digits
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
float | int
|
The number to format |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted number as a string |
Source code in openavmkit/utilities/format.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
fancy_format
fancy_format(num)
Formats a number in a pleasing and efficient way
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
float | int
|
The number to format |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted number as a string |
Notes
- Renders infinity as ∞
- Renders any null, nan, or similar values as "N/A"
- Shows decimals for small numbers
- Shows large numbers with suffixes (K for thousand, M for million, etc)
Source code in openavmkit/utilities/format.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
round_decimals_in_dict
round_decimals_in_dict(obj, places=2)
Recursively walk dicts/lists, and for every string:
- Finds all substrings that look like stringified floating point numbers
- Replaces each with its
float
value rounded toplaces
places - Returns a new structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
dict | list
|
The object to traverse |
required |
places
|
int
|
The number of decimal places to show. Defaults to 2. |
2
|
Returns:
Type | Description |
---|---|
dict | list
|
The newly formatted object |
Source code in openavmkit/utilities/format.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|