From ca08f3a486b90f0c13f91ec46830c18bd6433e99 Mon Sep 17 00:00:00 2001 From: hasnaat Date: Thu, 23 Apr 2026 00:23:44 +0500 Subject: [PATCH] fix(axes): format tick labels correctly for small numbers in exponential notation --- src/plots/cartesian/axes.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 38a8a7a8909..1fdcb984753 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -2210,9 +2210,27 @@ function numFormat(v, ax, fmtoverride, hover) { v = v.slice(0, Math.max(0, v.length + tickRound)); for(var i = tickRound; i < 0; i++) v += '0'; } else { - v = String(v); - var dp = v.indexOf('.') + 1; - if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, ''); + var vStr = String(v); + var ep = vStr.indexOf('e'); + if(ep >= 0) { + var mantissa = vStr.slice(0, ep); + var exponentStr = vStr.slice(ep); + var dp = mantissa.indexOf('.') + 1; + var exponentVal = parseInt(exponentStr.slice(1), 10); + var adjustedTickRound = tickRound + exponentVal; + if(dp) { + if(adjustedTickRound < 0) { + mantissa = mantissa.slice(0, dp - 1); + } else { + mantissa = mantissa.slice(0, dp + adjustedTickRound).replace(/\.?0+$/, ''); + } + } + v = mantissa + exponentStr; + } else { + v = vStr; + var dp = v.indexOf('.') + 1; + if(dp) v = v.slice(0, dp + tickRound).replace(/\.?0+$/, ''); + } } // insert appropriate decimal point and thousands separator v = Lib.numSeparate(v, ax._separators, separatethousands);