{"record":{"id":"a1c279f878c50957","repo":"BoundaryML/baml","slug":"to-fixed-method-takes-at-most-1-argument-at","errorCode":null,"errorMessage":"to_fixed() method takes at most 1 argument at {:?}","messagePattern":"to_fixed\\(\\) method takes at most 1 argument at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":3003,"sourceCode":"                    meta.0\n                );\n            };\n            // Replace first occurrence only (matching JavaScript behavior)\n            let result = s.replacen(search.as_str(), replacement.as_str(), 1);\n            Ok(BamlValueWithMeta::String(result, meta.clone()))\n        }\n        \"to_fixed\" => {\n            let value = match receiver {\n                BamlValueWithMeta::Float(v, _) => *v,\n                BamlValueWithMeta::Int(v, _) => *v as f64,\n                _ => bail!(\n                    \"to_fixed() method only available on floats and ints at {:?}\",\n                    meta.0\n                ),\n            };\n\n            if args.len() > 1 {\n                bail!(\"to_fixed() method takes at most 1 argument at {:?}\", meta.0);\n            }\n\n            let digits = match args.first() {\n                Some(BamlValueWithMeta::Int(v, _)) => *v,\n                Some(_) => bail!(\"to_fixed() digits argument must be an int at {:?}\", meta.0),\n                None => 0,\n            };\n\n            let formatted = baml_vm::native::number_to_fixed(value, digits)\n                .map_err(|msg| anyhow::anyhow!(\"{msg} at {:?}\", meta.0))?;\n            Ok(BamlValueWithMeta::String(formatted, meta.clone()))\n        }\n        _ => bail!(\n            \"unknown method '{}' at {:?}, should have been caught during typechecking\",\n            method_name,\n            meta.0\n        ),\n    }","sourceCodeStart":2985,"sourceCodeEnd":3021,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2985-L3021","documentation":"The \"to_fixed\" method accepts at most 1 argument (the number of digits). The interpreter bails when more than one argument is passed, reporting the source span. Digits is optional and defaults to 0 when omitted.","triggerScenarios":"Calling num.to_fixed(2, true), to_fixed(2, \"round\"), or any call with 2+ arguments — usually a misunderstanding of the signature (digits only).","commonSituations":"Porting from languages with richer formatting APIs (e.g. Python format specs, Intl.NumberFormat options objects) and trying to pass options as extra parameters.","solutions":["Pass at most one integer argument: the digit count (0–N)","Remove extra arguments; rounding/formatting options are not supported here","Use 0 arguments to round to integer formatting by default"],"exampleFix":"// before\nlet out = price.to_fixed(2, \"usd\");\n// after\nlet out = price.to_fixed(2);","handlingStrategy":"validation","validationCode":"// at most 1 arg: num.to_fixed(digits?) — drop extras","typeGuard":null,"tryCatchPattern":"try { out = num.to_fixed(d); } catch (e) { log(\"to_fixed arity: \" + e); }","preventionTips":["Pass only the digit count","No options-object support — do not add trailing args","Omit the arg entirely for 0 digits"],"tags":["runtime","arity","numbers","baml"],"backgroundTag":"invalid-argument","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}