@@ -2214,9 +2214,6 @@ function numFormat(v, ax, fmtoverride, hover) {
22142214
22152215 if ( tickformat ) return ax . _numFormat ( tickformat ) ( v ) . replace ( / - / g, MINUS_SIGN ) ;
22162216
2217- // 'epsilon' - rounding increment
2218- var e = Math . pow ( 10 , - tickRound ) / 2 ;
2219-
22202217 // exponentFormat codes:
22212218 // 'e' (1.2e+6, default)
22222219 // 'E' (1.2E+6)
@@ -2231,27 +2228,27 @@ function numFormat(v, ax, fmtoverride, hover) {
22312228 // take the sign out, put it back manually at the end
22322229 // - makes cases easier
22332230 v = Math . abs ( v ) ;
2231+
2232+ // 'epsilon' - rounding increment
2233+ const e = Math . pow ( 10 , - tickRound ) / 2 ;
22342234 if ( v < e ) {
22352235 // 0 is just 0, but may get exponent if it's the last tick
22362236 v = '0' ;
22372237 isNeg = false ;
22382238 } else {
2239- v += e ;
22402239 // take out a common exponent, if any
22412240 if ( exponent ) {
22422241 v *= Math . pow ( 10 , - exponent ) ;
22432242 tickRound += exponent ;
22442243 }
22452244 // round the mantissa
2246- if ( tickRound === 0 ) v = String ( Math . floor ( v ) ) ;
2247- else if ( tickRound < 0 ) {
2245+ if ( tickRound === 0 ) {
22482246 v = String ( Math . round ( v ) ) ;
2249- v = v . slice ( 0 , Math . max ( 0 , v . length + tickRound ) ) ;
2250- for ( var i = tickRound ; i < 0 ; i ++ ) v += '0' ;
2247+ } else if ( tickRound < 0 ) {
2248+ const roundingMagnitude = Math . pow ( 10 , - tickRound ) ;
2249+ v = String ( Math . round ( v / roundingMagnitude ) * roundingMagnitude ) ;
22512250 } else {
2252- v = String ( v ) ;
2253- var dp = v . indexOf ( '.' ) + 1 ;
2254- if ( dp ) v = v . slice ( 0 , dp + tickRound ) . replace ( / \. ? 0 + $ / , '' ) ;
2251+ v = v . toFixed ( Math . min ( 20 , tickRound ) ) . replace ( / \. ? 0 + $ / , '' ) ;
22552252 }
22562253 // insert appropriate decimal point and thousands separator
22572254 v = Lib . numSeparate ( v , ax . _separators , separatethousands ) ;
0 commit comments