baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
16.49k stars 2.41k forks source link

number显示组件精度问题 #10566

Open arenaswan opened 3 days ago

arenaswan commented 3 days ago

描述问题:

当kilobitSeparator配置为false时,precision配置的值大于0,小数位最后面出现的0没有显示出来,当kilobitSeparator为true时没有这个问题

截图或视频:

image image

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

  1. 你是如何使用 amis 的? npm

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在 6.5.0

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

    {
    "type": "page",
    "body": {
    "type": "number",
    "value": "13525646.30",
    "kilobitSeparator": false,
    "precision": 2
    }
    }
  4. 操作步骤 粘贴上述代码到渲染器中即可复现。

donglixiaoche commented 1 day ago

看了下代码

image

packages/amis/src/renderers/Number.tsxgetMiniDecimal 处理了带精度的字符串,并且做了 toNumber 的处理,如果精度不够用 “0” 来补充末尾的话,专成 number 会导致精度丢失。

不知道直接改成 value = toFixed(num2str(value), '.', precision); 是不是合理的处理方式