{"record":{"id":"20dc850ca2f6b5a7","repo":"BoundaryML/baml","slug":"to-fixed-digits-argument-must-be-an-int-at","errorCode":null,"errorMessage":"to_fixed() digits argument must be an int at {:?}","messagePattern":"to_fixed\\(\\) digits argument must be an int at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":3008,"sourceCode":"            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    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::path::PathBuf;","sourceCodeStart":2990,"sourceCodeEnd":3026,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2990-L3026","documentation":"When to_fixed receives an argument, it must be an Int (the number of decimal digits). The interpreter matches args.first() and bails on any non-Int value (float, string, bool, null, etc.), reporting the source span.","triggerScenarios":"Calling num.to_fixed(\"2\"), to_fixed(2.0), to_fixed(someString), or passing null where the digits count should be.","commonSituations":"A digits value computed from LLM output that came back as a float or string; copying code where 2 was written but a variable holding a float was substituted.","solutions":["Pass an integer literal or an Int-typed variable for digits","Convert a float digits value to int before calling (e.g. truncate/round)","Default to omitting the argument (0 digits) if no meaningful count is available"],"exampleFix":"// before (digits came from LLM as float)\nlet out = value.to_fixed(digits);\n// after\nlet out = value.to_fixed(digits.ToInt());","handlingStrategy":"type-guard","validationCode":"// digits must be int: if (d is int) { num.to_fixed(d); }","typeGuard":"fn is_int(v: Value) -> bool { matches!(v, Value::Int(_)) }","tryCatchPattern":"try { out = num.to_fixed(d); } catch (e) { out = num.to_fixed(0); }","preventionTips":["Use integer literals for precision","Truncate float digit counts first","Ensure dynamic digits come from int-typed fields"],"tags":["runtime","type-mismatch","arguments","numbers"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}