Avram <pyt...@avram.us> added the comment: I looked through a lot of the suggested libraries and they all seemed either too specific to an implementation or didn't fully implement compatibility. So I created Prefixed to prove out the implementation of of an expanded format specification for float would look like.
It implements 3 new format types: - h: SI Decimal prefix (..., n, μ, m, k, M, G, ...) - j: IEC Binary prefix (Ki, Mi, Gi, ...) - J: Shortened IEC Binary prefix (K, M, G, ...) It also implements a new flag, '!' that will add a space before the prefix. For now, the math is pretty simple, if you cross a magnitude level it will go to that prefix. So 999 would be '999' and 1000 would be 1k. I was thinking another format specification option '%' followed by a digit could be used to set the threshold of when to switch, so f'{950.0:%5.2h}' would be '0.95k', but f'{949.0:%5.2h}' would be '949.00'. Was going to think about it a little more before implementing. I'd appreciate feedback on the library. Issues can be submitted here: https://github.com/Rockhopper-Technologies/prefixed/issues https://pypi.org/project/prefixed/ ---------- nosy: +aviso _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31749> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com