Prefixed provides an alternative implementation of the built-in `float` which supports formatted output with SI (decimal) and IEC (binary) prefixes. The library is actively maintained with regular updates addressing bug fixes, new SI prefixes, and improvements to string parsing and formatting behavior.
pip install prefixedVerified import paths — ran on the pinned version, not inferred.
Initialize `prefixed.Float` objects and format them using f-strings with SI ('h', 'H') or IEC ('k', 'K', 'm', 'M') prefixes. Precision can indicate significant digits for 'H', 'K', 'M' types. String initialization also recognizes SI and IEC prefixes.
Review usage of `!` flag. If you relied on the space being dropped when no prefix was present, switch to using `!!`. Otherwise, no action is needed, as `!` now consistently adds a space.
Replace 'j' with 'k' and 'J' with 'm' in your format strings.
Ensure input strings adhere to the format of a number followed by an optional single space, then an optional prefix (e.g., '10 k', '500m', '2Ki').
Upgrade to version 0.8.0 or later to ensure correct rounding behavior during prefix determination.
Be aware of this input/output distinction if your application processes or expects specific Unicode representations of the micro prefix.
Install the library using pip: `pip install prefixed`
Convert the `prefixed.Float` object to a string first using `str()` before applying string methods, or use f-string formatting to control its string representation. For example: `str(my_prefixed_float).replace('k', 'Kilo')` or `f'{my_prefixed_float:.2h}'.replace('k', 'Kilo')`Ensure the input string represents a valid number with an optional, correctly formatted prefix (e.g., '1.2k', '5MiB', '1000', '2.5G'). Pre-process the string to remove any unexpected characters if necessary. Example: `Float('1.2k')` or `Float('5MiB')`Ensure that operations involving `prefixed.Float` are performed with standard numeric types (`int`, `float`) or other `prefixed.Float` instances. If operating with a special numeric type like `decimal.Decimal`, convert one of the operands to be compatible, e.g., `prefixed.Float(my_decimal_value)` or `float(my_prefixed_float) * my_decimal_value`.