def n_sigdigs_str(x, n):
    """Return a string representation of float x with n significant digits,
    where n > 0 is an integer.
    """
    format = "%." + str(int(n)) + "g"
    s = "%s" % float(format % x)
    if "." in s:
        # handle trailing ".0" when not one of the sig. digits
        pt_idx = s.index(".")
        if s[0] == "-":
            # pt_idx is one too large
            if pt_idx - 1 >= n:
                return s[:pt_idx]
        else:
            if pt_idx >= n:
                return s[:pt_idx]
    return s