fix(sync): clean floating-point decimals

This commit is contained in:
Aiden Cline
2026-08-03 14:38:26 -05:00
parent e45188c568
commit 267a67cd91
2 changed files with 18 additions and 1 deletions
+3 -1
View File
@@ -818,7 +818,9 @@ function formatInteger(n: number) {
}
function formatNumber(n: number) {
return Number.isInteger(n) ? formatInteger(n) : String(n);
if (Number.isInteger(n)) return formatInteger(n);
const normalized = Number(n.toPrecision(15));
return String(normalized);
}
function formatKey(value: string) {
+15
View File
@@ -1908,6 +1908,21 @@ test("formats interleaved as a root field before reasoning option tables", () =>
});
});
test("formats prices without floating-point noise", () => {
const content = formatToml({
cost: {
input: 0.14,
output: 0.28,
cache_read: 0.14 * 0.1,
},
});
expect(content).toContain("cache_read = 0.014");
expect(Bun.TOML.parse(content)).toMatchObject({
cost: { input: 0.14, output: 0.28, cache_read: 0.014 },
});
});
test("formats empty reasoning options outside the interleaved table", () => {
const content = formatToml({
id: "example/model",