Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Clamp fraction digits so formatValue keeps its never-throws contract (#314)
eeshsaxena8f38b543dae4
diff --git a/dash/src/format.ts b/dash/src/format.tsindex 54c33647..591fb71e 100644--- a/dash/src/format.ts+++ b/dash/src/format.ts@@ -132,7 +132,10 @@ export function formatValue(v: unknown, col: Pick<Column, 'type' | 'format'>): sconst p = readPattern(col.format)const isPct = p.pct || t === 'percent'const shown = isPct ? n * 100 : n- const dp = p.dp ?? (t === 'money' ? 2 : isPct ? 0 : shown % 1 === 0 ? 0 : 2)+ // Intl.NumberFormat throws for more than 100 fraction digits, so a format+ // string like "0.000…" (long enough) would break the never-throws contract.+ const rawDp = p.dp ?? (t === 'money' ? 2 : isPct ? 0 : shown % 1 === 0 ? 0 : 2)+ const dp = Math.max(0, Math.min(100, rawDp))const group = p.group || (!col.format && (t === 'money' || Math.abs(shown) >= 10_000))// A percent COLUMN prints a `%` even with no pattern saying so, which