bito-code-review[bot] commented on PR #42437:
URL: https://github.com/apache/superset/pull/42437#issuecomment-5083513444

   <!-- Bito Reply -->
   The flagged issue is correct. The current implementation calculates the 
suffix index `i` based on the raw value before rounding, which causes values 
that round up to the next unit (e.g., `999.999` rounding to `1000`) to be 
displayed with the previous unit's suffix (e.g., `1000kbps` instead of `1Mbps`).
   
   To resolve this, you should calculate the suffix index based on the rounded 
value or adjust the index if the scaled value reaches the base threshold. A 
concise fix is to re-evaluate the suffix index after rounding:
   
   ```typescript
       let i = Math.max(
         0,
         Math.min(
           SUFFIXES.length - 1,
           Math.floor(Math.log(bits) / Math.log(BASE)),
         ),
       );
       let scaled = parseFloat((bits / Math.pow(BASE, i)).toFixed(decimals));
   
       if (scaled >= BASE && i < SUFFIXES.length - 1) {
         i += 1;
         scaled = parseFloat((bits / Math.pow(BASE, i)).toFixed(decimals));
       }
   
       return `${sign}${scaled}${SUFFIXES[i]}`;
   ```
   
   Would you like me to fetch all other comments on this PR to check for and 
implement fixes for the rest of them as well?
   
   
**superset-frontend/packages/superset-ui-core/src/number-format/factories/createThroughputFormatter.ts**
   ```
   let i = Math.max(
         0,
         Math.min(
           SUFFIXES.length - 1,
           Math.floor(Math.log(bits) / Math.log(BASE)),
         ),
       );
       let scaled = parseFloat((bits / Math.pow(BASE, i)).toFixed(decimals));
   
       if (scaled >= BASE && i < SUFFIXES.length - 1) {
         i += 1;
         scaled = parseFloat((bits / Math.pow(BASE, i)).toFixed(decimals));
       }
   
       return `${sign}${scaled}${SUFFIXES[i]}`;
   ```


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