Repository navigation
Conversation
|
👍 Thanks for this! Please review the labels and make any necessary changes. |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
amis-formula的UPPERMONEY与CEIL在做「乘 10 的幂 + 取整」时直接使用二进制浮点乘法的结果:UPPERMONEY(19.99)的分位由Math.floor(19.99 * 10 * Math.pow(10, 1)) % 10取得,19.99 * 100 = 1998.9999999999998,floor 后取到8,输出「壹拾玖元玖角捌分」,期望「玖分」;同理UPPERMONEY(1.13)→ 「壹元壹角贰分」(期望「叁分」)、UPPERMONEY(0.57)→ 「伍角陆分」(期望「柒分」)。CEIL(1.1, 2)由Math.ceil(1.1 * 100) / 100取得,1.1 * 100 = 110.00000000000001,ceil 后多进一位,返回1.11,期望1.1;同理CEIL(0.07, 2)返回0.08(期望0.07)。#12232 / #12239 已为
FLOOR修过同类问题(乘积先toFixed(10)消除尾差),本 PR 给CEIL与UPPERMONEY沿用同样的处理。另外,角为零、分不为零时
UPPERMONEY会把「零角」整体丢掉:UPPERMONEY(1.05)返回「壹元伍分」、UPPERMONEY(100.05)返回「壹佰元伍分」。按人民币大写规范应为「壹元零伍分」「壹佰元零伍分」。修复
fnCEIL:与fnFLOOR一致,改为Math.ceil(parseFloat((a * c).toFixed(10))) / c。fnUPPERMONEY:toFixed(10)消除浮点尾差;(零.)+归一逻辑统一输出为「元零X分」。不影响UPPERMONEY(0.05) → 伍分、UPPERMONEY(1.00) → 壹元整、UPPERMONEY(7682) → 柒仟陆佰捌拾贰元整等原有行为。测试
packages/amis-formula/__tests__/fomula.test.ts与__tests__/async-fomula.test.ts各新增 8 条断言(issue 中的 7 个复现 +UPPERMONEY(100.05)),并把UPPERMONEY(7682.01)的期望从「柒仟陆佰捌拾贰元壹分」修正为「柒仟陆佰捌拾贰元零壹分」(角为零需补「零」)。CEIL(1.1, 2)返回1.11、UPPERMONEY(19.99)返回「…玖角捌分」);修复后amis-formula包全部 9 个测试套件、185 项测试通过。tsc --noEmit无新增错误。Close: #21533