A Python code snippet

I don’t know why there is no rounding function in the Python standard library that allows rounding to a certain number of significant figures. I come across the need to do this quite a lot.

The attached little function does the job. Perhaps something that does this job should make it into the math standard library in the future?

Photo by Hitesh Choudhary on Unsplash

--

--