Formatting floats in Python without superfluous zeros

Posted by TarGz on Stack Overflow See other posts from Stack Overflow or by TarGz
Published on 2010-03-14T00:27:39Z Indexed on 2010/03/14 3:25 UTC
Read the original article Hit count: 332

Filed under:
|
|

How to format a float so it does not containt the remaing zeros? In other words, I want the resulting string to be as short as possible..?

Like:

3 -> "3"
3. -> "3"
3.1 -> "3.1"
3.14 -> "3.14"
3.140 -> "3.14"

© Stack Overflow or respective owner

Related posts about python

Related posts about formatting