{"record":{"id":"10abdf96c359b9a4","repo":"nodejs/node","slug":"method-must-be-common-ceil-or-floor","errorCode":null,"errorMessage":"method must be common, ceil or floor","messagePattern":"method must be common, ceil or floor","errorType":"exception","errorClass":"FilterArgumentError","httpStatus":null,"severity":"error","filePath":"tools/inspector_protocol/jinja2/filters.py","lineNumber":795,"sourceCode":"    If you don't specify a method ``'common'`` is used.\n\n    .. sourcecode:: jinja\n\n        {{ 42.55|round }}\n            -> 43.0\n        {{ 42.55|round(1, 'floor') }}\n            -> 42.5\n\n    Note that even if rounded to 0 precision, a float is returned.  If\n    you need a real integer, pipe it through `int`:\n\n    .. sourcecode:: jinja\n\n        {{ 42.55|round|int }}\n            -> 43\n    \"\"\"\n    if not method in ('common', 'ceil', 'floor'):\n        raise FilterArgumentError('method must be common, ceil or floor')\n    if method == 'common':\n        return round(value, precision)\n    func = getattr(math, method)\n    return func(value * (10 ** precision)) / (10 ** precision)\n\n\n# Use a regular tuple repr here.  This is what we did in the past and we\n# really want to hide this custom type as much as possible.  In particular\n# we do not want to accidentally expose an auto generated repr in case\n# people start to print this out in comments or something similar for\n# debugging.\n_GroupTuple = namedtuple('_GroupTuple', ['grouper', 'list'])\n_GroupTuple.__repr__ = tuple.__repr__\n_GroupTuple.__str__ = tuple.__str__\n\n@environmentfilter\ndef do_groupby(environment, value, attribute):\n    \"\"\"Group a sequence of objects by a common attribute.","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/tools/inspector_protocol/jinja2/filters.py#L777-L813","documentation":"The round filter rounds a number to a given precision using one of three strategies: 'common' (Python's round), 'ceil', or 'floor' (via math.ceil/math.floor). Any other method name is invalid because there is no corresponding rounding function to dispatch to.","triggerScenarios":"Calling {{ value|round(precision, method) }} with method not in ('common','ceil','floor') — e.g. {{ 4.2|round(1, 'up') }} or {{ x|round(0, 'nearest') }}.","commonSituations":"Assuming round supports arbitrary rounding modes (banker's, half-up, truncate); passing a locale-translated method name.","solutions":["Use one of: 'common', 'ceil', or 'floor' (these are the only supported methods).","For truncation use {{ value|round(0, 'floor')|int }} or multiply/integer-divide manually.","Compute rounding in Python and pass the result to the template if you need a non-supported mode."],"exampleFix":"{# before #}\n{{ 4.7|round(0, 'up') }}\n\n{# after #}\n{{ 4.7|round(0, 'ceil') }}","handlingStrategy":"validation","validationCode":"import math\nALLOWED = ('common', 'ceil', 'floor')\nif method not in ALLOWED:\n    raise ValueError('round method must be one of %r' % (ALLOWED,))","typeGuard":"def is_round_method(value: str) -> bool:\n    return value in ('common', 'ceil', 'floor')","tryCatchPattern":"from jinja2.exceptions import FilterArgumentError\ntry:\n    out = env.call_filter('round', value, args=(precision, method))\nexcept FilterArgumentError:\n    out = env.call_filter('round', value, args=(precision, 'common'))","preventionTips":["Document the three supported methods anywhere round is exposed.","Restrict the method input to a fixed dropdown in any UI that drives it."],"tags":["jinja2","filter","round","validation"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}