public static function padNumber(int $val, int $len, bool $trim = false)
    {
        $result = sprintf("%0${len}d", $val);
        if (strlen($result) > $len) {
            if ($trim) {
                return substr($result, - $len);
            } else {
                throw new \LengthException('Value overflows maximum length');
            }
        }
        return $result;
    }