You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The toSafeString function contains complex string manipulation and regex logic for converting numbers. Review the logic for handling numbers with many decimal places and large integers to ensure it correctly formats all edge cases without introducing rounding errors or performance issues.
exportfunctiontoSafeString(number: number|string): string{// Use native Number.toString when it is NaN or non-scientific notationconstnativeNumberStr=number.toString();if(Number.isNaN(+number)||!nativeNumberStr.includes('e')){returnnativeNumberStr;}try{constisNegative=number<0;constabsoluteValue=Math.abs(+number);// Get decimal lengthconstdigitLength=NP.digitLength(absoluteValue);// Convert decimal to integerconstintegerNum=NP.float2Fixed(absoluteValue);// Convert integer to non-scientific notation stringconstintegerStr=integerNum.toString().replace(/e\+(\d+)/i,(_,$1)=>newArray(+$1).fill(0).join(''));return`${isNegative ? '-' : ''}${digitLength===0 ? integerStr : integerStr.replace(newRegExp(`\\d{1,${digitLength}}$`),(match)=>{constdecimalStr=`${newArray(digitLength).fill(0).join('')}${match}`.slice(-digitLength);return`${integerStr.length<=digitLength ? 0 : ''}.${decimalStr}`;})}`;}catch(e){// If any error occurs, fallback to native string conversion}returnnativeNumberStr;}
The getStringValue function now uses toSafeString for numbers without a precision set. Validate that the fallback to the native string conversion in toSafeString (when an error occurs) is robust and does not cause unexpected display issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)featurebranch and othersshould be submitted to
mainbranch)