{"record":{"id":"93f4d8511e02e44f","repo":"reflex-dev/reflex","slug":"unknown-format-code-format-spec-for-object-of","errorCode":null,"errorMessage":"Unknown format code '{format_spec}' for object of type 'NumberVar'. It is only supported to use ',', '_', and '.f' for float numbers.If possible, use computed variables instead: https://reflex.dev/docs/vars/computed-vars/","messagePattern":"Unknown format code '(.+?)' for object of type 'NumberVar'\\. It is only supported to use ',', '_', and '\\.f' for float numbers\\.If possible, use computed variables instead: https://reflex\\.dev/docs/vars/computed-vars/","errorType":"exception","errorClass":"VarValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/number.py","lineNumber":491,"sourceCode":"            format_spec\n            and format_spec[-1] == \"f\"\n            and format_spec[0] == \".\"\n            and format_spec[1:-1].isdigit()\n        ):\n            how_many_decimals = int(format_spec[1:-1])\n            return f\"{get_decimal_string_operation(self, Var.create(how_many_decimals), Var.create(separator))}\"\n\n        if not format_spec and separator:\n            return (\n                f\"{get_decimal_string_separator_operation(self, Var.create(separator))}\"\n            )\n\n        if format_spec:\n            msg = (\n                f\"Unknown format code '{format_spec}' for object of type 'NumberVar'. It is only supported to use ',', '_', and '.f' for float numbers.\"\n                \"If possible, use computed variables instead: https://reflex.dev/docs/vars/computed-vars/\"\n            )\n            raise VarValueError(msg)\n\n        return super().__format__(format_spec)\n\n\ndef binary_number_operation(\n    func: Callable[[NumberVar, NumberVar], str],\n) -> Callable[[number_types, number_types], NumberVar]:\n    \"\"\"Decorator to create a binary number operation.\n\n    Args:\n        func: The binary number operation function.\n\n    Returns:\n        The binary number operation.\n    \"\"\"\n\n    @var_operation\n    def operation(lhs: NumberVar, rhs: NumberVar):","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/number.py#L473-L509","documentation":"NumberVar.__format__ only supports a small set of format specs: ',' (thousands separator), '_' (digit grouping), and float precision like '.2f'. Any other format code (e.g. 'x', 'b', 'e', '%') cannot be translated to JavaScript, so VarValueError is raised.","triggerScenarios":"Applying an unsupported format spec to a NumberVar, e.g. f\"{self.value:x}\", f\"{n:e}\", f\"{p:%}\", or fill/align specs like f\"{n:>8}\".","commonSituations":"Copying Python format strings into Reflex templates; trying to render hex/binary/percent from a number var directly; forgetting that formats are limited because they compile to JS.","solutions":["Restrict specs to ',', '_', or '.Nf' (e.g. f\"{value:,.2f}\").","For other formats, use a computed var (@rx.var) that formats the value in Python and returns a string.","Do the conversion client-side logic manually or precompute the string on the backend."],"exampleFix":"# before\nrx.text(f\"{State.amount:%}\")\n\n# after\nclass State(rx.State):\n    amount: float = 0.1\n    @rx.var\n    def amount_pct(self) -> str:\n        return f\"{self.amount:%}\"\n# rx.text(State.amount_pct)","handlingStrategy":"validation","validationCode":"import re\n\ndef spec_supported(spec: str) -> bool:\n    return bool(re.fullmatch(r\"[,_]?[0-9]*\\.?[0-9]*f?\", spec)) and not set(spec) - set(',._0123456789f')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stick to ',', '_', and '.Nf' format specs on NumberVars.","Use computed vars for exotic formats (hex, percent, exponent).","Test format strings when porting Python UI code."],"tags":["reflex","numbervar","format-spec","var-value-error"],"backgroundTag":"var-unsupported-format-spec","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}