in C #, I can do (#. ####) that prints up to 4 significant digits after the decimal point. 1.2 → 1.2 1.234 → 1.234 1.23456789 → 1.2345
Afaik, in python, there is only c-style% .4f, which will always print up to 4 decimal places, filled with zeros at the end, if necessary. I do not want these 0s.
Any suggestions on what is the cleanest way to achieve what I need?
One possible solution is to print it first and crop the 0s ending, but hoping to find smarter ways.
source
share