Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/util/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@ export function round(x: number | string, precision: number, returnStr?: boolean
// precision utils (such as getAcceptableTickPrecision) may return NaN.
return returnStr ? '' + x : +x;
}
// Avoid range error
precision = mathMin(mathMax(0, precision), TO_FIXED_SUPPORTED_PRECISION_MAX);
// Avoid range error. Do not clamp large precision to 20 because it may
// over-round tiny values such as 3e-21 to zero.
if (precision > TO_FIXED_SUPPORTED_PRECISION_MAX) {
return returnStr ? '' + x : +x;
}
precision = mathMax(0, precision);
// PENDING: 1.005.toFixed(2) is '1.00' rather than '1.01'
x = (+x).toFixed(precision);
return (returnStr ? x : +x);
Expand Down
23 changes: 23 additions & 0 deletions test/ut/spec/scale/interval.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions test/ut/spec/util/number.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.