{"record":{"id":"67546ac77816b4ca","repo":"twigphp/Twig","slug":"the-round-filter-only-supports-the-common-ceil-and-floor","errorCode":null,"errorMessage":"The \"round\" filter only supports the \"common\", \"ceil\", and \"floor\" methods.","messagePattern":"The \"round\" filter only supports the \"common\", \"ceil\", and \"floor\" methods\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/Extension/CoreExtension.php","lineNumber":678,"sourceCode":"     *\n     * @param int|float|string|null   $value     The value to round\n     * @param int|float               $precision The rounding precision\n     * @param 'common'|'ceil'|'floor' $method    The method to use for rounding\n     *\n     * @return float The rounded number\n     *\n     * @internal\n     */\n    public static function round($value, $precision = 0, $method = 'common')\n    {\n        $value = (float) $value;\n\n        if ('common' === $method) {\n            return round($value, $precision);\n        }\n\n        if ('ceil' !== $method && 'floor' !== $method) {\n            throw new RuntimeError('The \"round\" filter only supports the \"common\", \"ceil\", and \"floor\" methods.');\n        }\n\n        return $method($value * 10 ** $precision) / 10 ** $precision;\n    }\n\n    /**\n     * Formats a number.\n     *\n     * All of the formatting options can be left null, in that case the defaults will\n     * be used. Supplying any of the parameters will override the defaults set in the\n     * environment object.\n     *\n     * @param mixed       $number       A float/int/string of the number to format\n     * @param int|null    $decimal      the number of decimal points to display\n     * @param string|null $decimalPoint the character(s) to use for the decimal point\n     * @param string|null $thousandSep  the character(s) to use for the thousands separator\n     */\n    public function formatNumber($number, $decimal = null, $decimalPoint = null, $thousandSep = null): string","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Extension/CoreExtension.php#L660-L696","documentation":"The Twig `round` filter accepts a method argument that must be one of \"common\", \"ceil\", or \"floor\". CoreExtension::round validates the method and throws a RuntimeError for anything else, because it later invokes $method($value) directly and an arbitrary callable/string would be unsafe or undefined.","triggerScenarios":"Calling {{ 2.7|round(1, 'up') }}, {{ x|round(0, 'truncate') }}, or passing any method string other than exactly 'common', 'ceil', or 'floor' (case-sensitive).","commonSituations":"Typos like 'ceiling' or 'round-up'; translating method names; copying a math-library method name that Twig does not support; dynamically passing a method from config with an unsupported value.","solutions":["Use one of the supported methods: 'common' (default), 'ceil', or 'floor'.","For 'ceiling' intent, use {{ x|round(0, 'ceil') }}; for truncation toward zero on positives use 'floor'.","If the method comes from user input/config, whitelist-validate it against ['common','ceil','floor'] before rendering."],"exampleFix":"// before (template)\n{{ 2.7|round(0, 'ceiling') }}\n\n// after\n{{ 2.7|round(0, 'ceil') }}","handlingStrategy":"validation","validationCode":"// Whitelist the method before rendering\n$allowed = ['common', 'ceil', 'floor'];\n$method = \\in_array($method, $allowed, true) ? $method : 'common';","typeGuard":"function isRoundMethod($m): bool { return \\is_string($m) && \\in_array($m, ['common', 'ceil', 'floor'], true); }","tryCatchPattern":"try {\n    $out = \\Twig\\Extension\\CoreExtension::round($value, $precision, $method);\n} catch (\\Twig\\Error\\RuntimeError $e) {\n    $out = \\round($value, $precision); // fall back to 'common'\n}","preventionTips":["Only use 'common', 'ceil', 'floor' as the second argument of round.","Validate user/config-supplied method names against a whitelist.","Note method names are case-sensitive and unabbreviated ('ceil', not 'ceiling')."],"tags":["twig","filter","invalid-enum-value","round"],"backgroundTag":"invalid-enum-value","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}