From a3abb0eff291b269daf809c75d585e9bcedc4442 Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Thu, 23 May 2024 22:16:30 -0400 Subject: [PATCH] Make serializeNumber fix IEEE754 errors by default --- src/util.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util.js b/src/util.js index 450ae9377..515c21fe1 100644 --- a/src/util.js +++ b/src/util.js @@ -24,12 +24,14 @@ export function type (o) { return (str.match(/^\[object\s+(.*?)\]$/)[1] || "").toLowerCase(); } -export function serializeNumber (n, {precision, unit }) { +export function serializeNumber (n, {precision = 16, unit }) { if (isNone(n)) { return "none"; } - return toPrecision(n, precision) + (unit ?? ""); + n = +toPrecision(n, precision); + + return n + (unit ?? ""); } /**