I have to export numbers as text using python and experience several ways of not doing what i want. There is string.format(), old % string format, and F-Strings - plenty of very smart ways of formatting things into strings, but I can't find a simple way to produce a string from a number that meets my criteria of having:
- Decimal separator from locale.
- No thousand separator.
- Infinite (~) number of significant integer digits, but at least one zero.
- Specified number of significant decimal digits - with no decimal separator if no significant decimals.
- No scientific notation (e-crap).
Not a very exotic request? Have I missed something obvious?
Using locale, floor and f-strings it is quite easy to make a string like you want:
print(f"a = {a_string}")
This gives me:
because my locale decimal separator is "." and you can set the number of decimals you want by changing the ":.1g" to ":.Xg", X being the number of decimals you want.