import math


def round_sig_figs(x, sf):
    """Round a number `x' down to a number of significant figures `sf'."""
    if abs(x) < 1e-18:
        return 0
    else:
        # https://stackoverflow.com/a/3411435/313032, Roy Hyunjin Han
        return round(x, -int(math.floor(math.log10(abs(x)))) + (sf - 1))