no-hup opened a new issue, #43548:
URL: https://github.com/apache/superset/issues/43548

   
   ## Bug description
   
   `createMemoryFormatter` in `@superset-ui/core` (used for the `MEMORY_*` 
d3-style
   formats in charts/tables) mishandles two edge ranges:
   
   1. Values between 0 and 1 byte: the suffix index is computed as
      `Math.floor(Math.log(absValue) / Math.log(base))`, which goes negative for
      `absValue < 1`, so `suffixes[i]` is `undefined`. `formatter(0.5)` returns
      `"500undefined"` instead of `"0.5B"`. Negative fractional values hit the
      same path (`-0.25` -> `"-250undefined"`).
   
   2. Values that round up to the base: `formatter(999999)` scales to `999.999`,
      which `toFixed(2)` rounds to `1000.00`, so the output is `"1000kB"` 
instead
      of `"1MB"`. Same for binary mode near `1024`.
   
   ## How to reproduce
   
   ```ts
   import { createMemoryFormatter } from '@superset-ui/core';
   const f = createMemoryFormatter();
   f(0.5);    // "500undefined"  (expected "0.5B")
   f(999999); // "1000kB"        (expected "1MB")
   ```
   
   ## Expected
   
   Sub-byte values keep the `B` unit; values that round to the base roll over to
   the next unit.
   


-- 
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