【问题标题】:angular-handsontable display decimal valueangular-handsontable 显示十进制值
【发布时间】:2018-10-25 18:07:20
【问题描述】:

我在我的应用程序中使用 angular-handsontable。我需要显示一个十进制值(22.45)而不四舍五入到最接近的值。当我使用时,

columns: ({ type: string; numericFormat: { pattern: string; }; } | {})[];
this.data = [     
      ['99.259999999999']
      ];

 this.columns = [
{type: 'numeric', numericFormat: { pattern: '0.00%' }}
];

我的值显示为 99,而不是 99.25。我们如何使用handsontable 实现这一目标

【问题讨论】:

    标签: angular decimal display handsontable


    【解决方案1】:

    尝试在使用前迭代您的数据数组,并为每个值应用toFixedMath.round 函数。

    截取小数

    this.data.forEach(item => {
        item = item.toFixed(2);
    });
    

    四舍五入

     this.data.forEach(item => {
            item = Math.round(item * 100) / 100;
        });
    

    【讨论】:

    • 我应该在哪里使用 toFixed?到值或格式级别
    • 在你的情况下,它可能是这样的this.data[0].toFixed(2),即使你有更多的值,你也可以在使用它之前给出格式。通过迭代数组。
    • 可以请详细说明或创建一个小提琴。没找到在哪里添加
    • 准备好我修改了我的帖子。
    • 好的,toFixed 只是为了明确一点,这个函数不做任何一轮,如果你有 12.259,你会得到前两位小数 12.25
    猜你喜欢
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    相关资源
    最近更新 更多