Skip to content

Commit

Permalink
Make serializeNumber fix IEEE754 errors by default
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed May 24, 2024
1 parent 9b02d6c commit a3abb0e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "");
}

/**
Expand Down

0 comments on commit a3abb0e

Please sign in to comment.