Skip to content

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

@dontbmh

Description

@dontbmh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions