Skip to content

Commit 8908ff9

Browse files
Apply maintainer suggestion: use toFixed instead of string manipulation
1 parent ca08f3a commit 8908ff9

1 file changed

Lines changed: 1 addition & 21 deletions

File tree

src/plots/cartesian/axes.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,27 +2210,7 @@ function numFormat(v, ax, fmtoverride, hover) {
22102210
v = v.slice(0, Math.max(0, v.length + tickRound));
22112211
for(var i = tickRound; i < 0; i++) v += '0';
22122212
} else {
2213-
var vStr = String(v);
2214-
var ep = vStr.indexOf('e');
2215-
if(ep >= 0) {
2216-
var mantissa = vStr.slice(0, ep);
2217-
var exponentStr = vStr.slice(ep);
2218-
var dp = mantissa.indexOf('.') + 1;
2219-
var exponentVal = parseInt(exponentStr.slice(1), 10);
2220-
var adjustedTickRound = tickRound + exponentVal;
2221-
if(dp) {
2222-
if(adjustedTickRound < 0) {
2223-
mantissa = mantissa.slice(0, dp - 1);
2224-
} else {
2225-
mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, '');
2226-
}
2227-
}
2228-
v = mantissa + exponentStr;
2229-
} else {
2230-
v = vStr;
2231-
var dp = v.indexOf('.') + 1;
2232-
if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, '');
2233-
}
2213+
v = v.toFixed(Math.max(0, Math.min(20, tickRound))).replace(/\.?0+$/, '');
22342214
}
22352215
// insert appropriate decimal point and thousands separator
22362216
v = Lib.numSeparate(v, ax._separators, separatethousands);

0 commit comments

Comments
 (0)