Skip to content

fix(core): keep sign of negative numbers in convertToAbbreviationString - #2850

Merged
danielleroux merged 1 commit into
siemens:mainfrom
kwy404:fix/abbreviation-negative-sign
Sep 28, 2026
Merged

danielleroux merged 1 commit into
siemens:mainfrom
kwy404:fix/abbreviation-negative-sign

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What is the current behavior?

Root cause: convertToAbbreviationString (exported from @siemens/ix) compares Math.abs(num) against each unit and then overwrites num with the rounded absolute value, so the minus sign is lost. convertToAbbreviationString(-1500) returns 1.5K and convertToAbbreviationString(-2000000) returns 2M. Numbers with an absolute value below 1000 are not affected because they never enter that branch.

GitHub Issue Number: none

What is the new behavior?

  • The rounded absolute value is multiplied by Math.sign(num), so -1500 returns -1.5K and -2000000 returns -2M. Positive numbers are unchanged, and rounding stays symmetric (-1450 gives -1.5K like 1450 gives 1.5K).
  • Added utils/test/rwd.util.spec.ts. The negative case fails before the fix (expected '1.5K' to be '-1.5K') and passes after it.
  • Added a patch changeset for @siemens/ix.

Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • Accessibility (a11y) features were implemented
  • Internationalization (i18n) - no hard coded strings
  • Responsiveness - components handle viewport changes and content overflow gracefully
  • Add or update a Storybook story
  • Documentation was reviewed/updated siemens/ix-docs
  • Unit tests were added/updated and pass (pnpm test)
  • Visual regression tests were added/updated and pass (Guide)
  • Static code analysis passes (pnpm lint)
  • Successful compilation (pnpm build, changes pushed)

Help & support

Validation: the new spec passes with vitest run --project spec, ESLint and Prettier pass on the changed files, and stencil build succeeds for @siemens/ix. No visual change, so no visual regression or docs updates are needed.

Summary by CodeRabbit

  • Bug Fixes
    • Negative values now retain their minus sign when displayed in abbreviated formats, such as -1.5K and -2M.
@kwy404
kwy404 requested a review from a team as a code owner September 26, 2026 16:43
@kwy404
kwy404 requested a review from danielleroux September 26, 2026 16:43
@changeset-bot

changeset-bot Bot commented Sep 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b3af10e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@siemens/ix Patch
@siemens/ix-angular Patch
@siemens/ix-react Patch
@siemens/ix-vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for ix-storybook ready!

Name Link
🔨 Latest commit b3af10e
🔍 Latest deploy log https://app.netlify.com/projects/ix-storybook/deploys/6ab7f632510c0500087b10f3
😎 Deploy Preview https://deploy-preview-2850--ix-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: siemens/ix/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 704238e4-130d-4b97-b1a2-cbfdfddd6f56

📥 Commits

Reviewing files that changed from the base of the PR and between 94b305c and b3af10e.

📒 Files selected for processing (3)
  • .changeset/fix-abbreviation-negative-sign.md
  • packages/core/src/components/utils/rwd.util.ts
  • packages/core/src/components/utils/test/rwd.util.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

convertToAbbreviationString now preserves the sign of negative values when it abbreviates them. Tests cover positive and negative values at thousand and million scales.

Changes

Abbreviation Sign Handling

Layer / File(s) Summary
Sign preservation and validation
packages/core/src/components/utils/rwd.util.ts, packages/core/src/components/utils/test/rwd.util.spec.ts, .changeset/fix-abbreviation-negative-sign.md
The utility applies the input sign to the rounded abbreviated value. Tests cover positive and negative values at thousand and million scales. A patch changeset describes the fix.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to b3af1

Negative abbreviated values retain their sign, with tests for thousand and million values. No actionable merge-blocking risk is evident; the PR appears ready after normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to b3af1

The change affects 1 system.

Changed systems: packages/core

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/core (ui) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/core/src/components/utils/rwd.util.ts: Abbreviated values are now rounded from their absolute magnitude and multiplied by the input’s sign; previously, rounding the magnitude discarded negative signs.
  • observed — Modified behavior in packages/core/src/components/utils/test/rwd.util.spec.ts: Added tests asserting abbreviation output for positive and negative values at the thousand and million scales.
  • observed — Modified behavior in .changeset/fix-abbreviation-negative-sign.md: Adds a patch changeset for @siemens/ix stating that convertToAbbreviationString previously omitted the minus sign when abbreviating negative numbers.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving the sign of negative numbers in convertToAbbreviationString.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@danielleroux

Copy link
Copy Markdown
Collaborator

Looks good thank you 🎉

@danielleroux
danielleroux merged commit 322fbff into siemens:main Sep 28, 2026
21 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants