twigphp/Twig · error · RuntimeError
The "round" filter only supports the "common", "ceil", and…
Error message
The "round" filter only supports the "common", "ceil", and "floor" methods.
What it means
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.
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.
Example fix
// before (template)
{{ 2.7|round(0, 'ceiling') }}
// after
{{ 2.7|round(0, 'ceil') }} Defensive patterns
Strategy: validation
Validate before calling
// Whitelist the method before rendering $allowed = ['common', 'ceil', 'floor']; $method = \in_array($method, $allowed, true) ? $method : 'common';
Type guard
function isRoundMethod($m): bool { return \is_string($m) && \in_array($m, ['common', 'ceil', 'floor'], true); } Try / catch
try {
$out = \Twig\Extension\CoreExtension::round($value, $precision, $method);
} catch (\Twig\Error\RuntimeError $e) {
$out = \round($value, $precision); // fall back to 'common'
} Prevention
- 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').
When it happens
Trigger: Calling {{ 2.7|round(1, 'up') }}, {{ x|round(0, 'truncate') }}, or passing any method string other than exactly 'common', 'ceil', or 'floor' (case-sensitive).
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- The " " filter is part of the , which is not…
- The "replace" filter expects a sequence or a mapping, got
- The "merge" filter expects a sequence or a mapping, got
- The "sort" filter expects a sequence or a mapping, got
- The "batch" filter expects a sequence or a mapping, got
AI-assisted analysis of twigphp/Twig@a414c3a491 (2026-09-13).
Data as JSON: /api/errors/67546ac77816b4ca.
Report an issue: GitHub.
Appendix: source
Thrown at src/Extension/CoreExtension.php:678
*
* @param int|float|string|null $value The value to round
* @param int|float $precision The rounding precision
* @param 'common'|'ceil'|'floor' $method The method to use for rounding
*
* @return float The rounded number
*
* @internal
*/
public static function round($value, $precision = 0, $method = 'common')
{
$value = (float) $value;
if ('common' === $method) {
return round($value, $precision);
}
if ('ceil' !== $method && 'floor' !== $method) {
throw new RuntimeError('The "round" filter only supports the "common", "ceil", and "floor" methods.');
}
return $method($value * 10 ** $precision) / 10 ** $precision;
}
/**
* Formats a number.
*
* All of the formatting options can be left null, in that case the defaults will
* be used. Supplying any of the parameters will override the defaults set in the
* environment object.
*
* @param mixed $number A float/int/string of the number to format
* @param int|null $decimal the number of decimal points to display
* @param string|null $decimalPoint the character(s) to use for the decimal point
* @param string|null $thousandSep the character(s) to use for the thousands separator
*/
public function formatNumber($number, $decimal = null, $decimalPoint = null, $thousandSep = null): stringView on GitHub (pinned to a414c3a491)