I'm looking for a string conversion function/module in Python that is based upon significant digits (figures). The usefulness for this functionality has come up several times, so it seems hard to believe that Python still doesn't have a function or module to do this easily. Does anyone know if anything new has come out? If not, would this be a good opportunity for a feature request?
Disclaimers:
- I realize that this is a topic that has several questions already, but most of them are several years old. I'm hoping something has been released recently, as useful as it seems.
- I also realize that it is relatively simple to write a function to do this manually, but I would prefer a module or (better) a built-in function for portability.
- I'm not looking for the output to be in exponential notation
Functionality examples:
>>> from somemodule import SDStr
>>> SDStr(num=1234, sigDigs=3)
'1230'
>>> SDStr(num=12.3456, sigDigs=4)
'12.35'
>>> SDStr(num=100, sigDigs=3)
'100.'
>>> SDStr(num=100.0, sigDigs=2)
'100'
>>> SDStr(num=100, sigDigs=4)
'100.0'
>>> SDStr(num=0.001234, sigDigs=2)
'0.0012'