sadpandajoe commented on code in PR #43620:
URL: https://github.com/apache/superset/pull/43620#discussion_r3886003907


##########
superset-frontend/packages/superset-ui-core/src/number-format/factories/createMemoryFormatter.ts:
##########
@@ -38,11 +38,19 @@ function formatMemory(
         : ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'RB', 'QB'];
       const base = binary ? 1024 : 1000;
 
-      const i = Math.min(
-        suffixes.length - 1,
-        Math.floor(Math.log(absValue) / Math.log(base)),
-      );
-      formatted = `${sign}${parseFloat((absValue / Math.pow(base, 
i)).toFixed(decimals))}${suffixes[i]}`;
+  let scaleIndex = absValue < 1 ? 0 : Math.floor(Math.log(absValue) / 
Math.log(base));
+  let i = Math.min(suffixes.length - 1, scaleIndex);
+
+  let scaledValue = absValue / Math.pow(base, i);
+
+  if (scaledValue >= base && i < suffixes.length - 1) {

Review Comment:
   This checks the unrounded mantissa, so values just below a unit boundary 
still render as an overflowing lower unit. For example, `999999` becomes 
`1000kB` and `1048575` becomes `1024KiB` instead of rolling over. Should the 
promotion check use the value after applying the configured rounding?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to