Skip to content
Advertisement

How to format very small numbers in python?

How to format 1.3435434533e-8 into 1.34e-8 in python? Keep only two digits. The round() method will round this number to zero.

Advertisement

Answer

The “g” formatting suffix on string mini-format language, used both by f-strings, and the .format method will do that:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement