import math


def _truncate(x, decimals):
    """
    Truncates a given number x to contain at most `decimals`.

    :param float x: Number which we want to truncate.
    :param int decimals: Maximum number of decimals that the result will
        contain.

    :returns float: Truncated result.
    """
    power = 10**decimals
    return math.trunc(power * x) / power