SyntaxFix
Write A Post
Hire A Developer
Questions
I modified indgar's solution to handle negative numbers and small numbers (including zero).
from math import log10, floor def round_sig(x, sig=6, small_value=1.0e-9): return round(x, sig - int(floor(log10(max(abs(x), abs(small_value))))) - 1)