Note: There is a more up to date version of this repository created by BebeSparkelSparkel with additional functionality available here: https://github.com/BebeSparkelSparkel/to-precision
Formatting floating point numbers to a specific number of significant digits in Python
For more information see my blog post on this topic.