Skip to content

amis-formula: UPPERMONEY and CEIL give wrong results from float multiplication (UPPERMONEY(19.99) gives 壹拾玖元玖角捌分, CEIL(1.1, 2) gives 1.11) #21533

Done

Description

@trackoor

描述问题:

UPPERMONEY and CEIL multiply by a power of ten and then floor or ceil the result. In binary floating point, 19.99 * 100 is slightly less than 1999 and 1.1 * 100 is slightly more than 110, so the last digit comes out wrong. #12232 / #12239 fixed this for FLOOR by rounding a * c with toFixed(10), but CEIL and UPPERMONEY still use the unrounded product.

Also, when 角 is zero and 分 is non-zero, UPPERMONEY drops 零: UPPERMONEY(1.05) returns 壹元伍分 and UPPERMONEY(100.05) returns 壹佰元伍分 instead of 壹元零伍分 and 壹佰元零伍分.

截图或视频:

N/A

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的?
    npm (amis-formula)

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在
    amis-formula@6.13.0 (latest; also on master 43a33ee in packages/amis-formula/src/evalutor.ts)

  3. 粘贴有问题的完整 amis schema 代码:

const amisFormula = require('amis-formula');
const opts = { evalMode: true };

amisFormula.evaluate('UPPERMONEY(19.99)', undefined, opts); // '壹拾玖元玖角捌分', expected '壹拾玖元玖角玖分'
amisFormula.evaluate('UPPERMONEY(1.13)', undefined, opts);  // '壹元壹角贰分',     expected '壹元壹角叁分'
amisFormula.evaluate('UPPERMONEY(0.57)', undefined, opts);  // '伍角陆分',         expected '伍角柒分'
amisFormula.evaluate('UPPERMONEY(1.05)', undefined, opts);  // '壹元伍分',         expected '壹元零伍分'
amisFormula.evaluate('CEIL(1.1, 2)', undefined, opts);      // 1.11,               expected 1.1
amisFormula.evaluate('CEIL(0.07, 2)', undefined, opts);     // 0.08,               expected 0.07
amisFormula.evaluate('CEIL(1.1)', undefined, opts);         // 1.11,               expected 1.1
  1. 操作步骤
    Run the snippet above with node after npm install amis-formula@6.13.0. Out of all cent amounts from 0.01 to 999.99, 7,669 produce the wrong 角 or 分 digit in fnUPPERMONEY (Math.floor(n * 10 * Math.pow(10, i)) % 10), and fnCEIL (Math.ceil(a * c) / c) rounds up exact two-decimal numbers whenever a * c has a positive float tail.

Credit: https://ucsbplse.github.io/

Activity

  1. github-actions commented on Nov 14, 2026

    @github-actions

    👍 Thanks for this!
    🏷 I have applied any labels matching special text in your issue.

    Please review the labels and make any necessary changes.

  2. go-888 commented on Nov 20, 2026

    @go-888

    项目都停更了, 你还发这个.

  3. added a commit that references this issue on Nov 21, 2026
    cb77667
  4. added a commit that references this issue on Nov 27, 2026
    9d75c38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions