react-component / react-component/mini-decimal

Causing an issue in react-component / input-number that -0 is displayed when precision is set to 0

Open
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7
Forks
4
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @rc-component/mini-decimal@1.1.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js b/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js
index 17c4ead..f707338 100644
--- a/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js
+++ b/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js
@@ -39,7 +39,7 @@ export function toFixed(numStr, separatorStr, precision) {
       return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
     }
     if (precision === 0) {
-      return numberWithoutDecimal;
+      return integerStr === '0' ? integerStr : numberWithoutDecimal;
     }
     return "".concat(numberWithoutDecimal).concat(separatorStr).concat(decimalStr.padEnd(precision, '0').slice(0, precision));
   }
diff --git a/node_modules/@rc-component/mini-decimal/lib/MiniDecimal.js b/node_modules/@rc-component/mini-decimal/lib/MiniDecimal.js
index 91e3663..ff588aa 100644
--- a/node_modules/@rc-component/mini-decimal/lib/MiniDecimal.js
+++ b/node_modules/@rc-component/mini-decimal/lib/MiniDecimal.js
@@ -58,7 +58,7 @@ function toFixed(numStr, separatorStr, precision) {
       return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
     }
     if (precision === 0) {
-      return numberWithoutDecimal;
+      return integerStr === '0' ? integerStr : numberWithoutDecimal;
     }
     return "".concat(numberWithoutDecimal).concat(separatorStr).concat(decimalStr.padEnd(precision, '0').slice(0, precision));
   }

This issue body was partially generated by patch-package.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the precision-zero handling in node_modules/@rc-component/mini-decimal/es/MiniDecimal.js and lib/MiniDecimal.js, using the supplied diff as the behavioral reference. Confirm that formatting a negative zero with precision set to 0 no longer displays -0, and check whether the corresponding package source or tests need the same change.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.