fix(input-number): input number 输入 0.00000001 会自动变成科学计数法 #3600
+102
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Background and context
input number 组件输入小数会变成科学计数法,0.000000001 -> 1e-8 , 这是机器影响用户体验。
并且 react 版本并不存在这个问题。
经过搜索发现早期 arco-design-vue是修复过这个问题的 arco-design/arco-design#865
问题复现路径:

在文档中就能复现
Solution
新增
toSafeString
工具函数来处理科学计数法转换修改
getStringValue
函数,使用toSafeString
替代原生的String()
方法使用
number-precision
库确保精确的数值转换📁
packages/web-vue/components/input-number/utils.ts
- 新增工具函数📁
packages/web-vue/components/input-number/input-number.tsx
- 修改核心逻辑📁
packages/web-vue/components/input-number/__test__/index.test.ts
- 添加测试用例How is the change tested?
添加并通过了组件测试用例。
1.234e5 => 123400
-0.000000000000000000001 => -0.000000000000000000001
等,具体文件在 packages/web-vue/components/input-number/test/index.test.ts`
Changelog
Checklist:
npm run test
)feature
branch and othersshould be submitted to
main
branch)