【问题标题】:How to always show 2 decimal points after dot in reactjs [duplicate]如何在reactjs中的点后始终显示2个小数点[重复]
【发布时间】:2020-10-27 12:33:37
【问题描述】:

我在 reactjs 中填充了一个表格。我在那里有一个显示数字的列,现在我有一个要求,在点之后我总是必须显示 2 个数字。

如上图所示,我的值为 26.1,但我必须显示 26.10。

我已经尝试如下

<Column
      field={(object) =>
        object.amount !== null ? bsUtils.formatToUSD(object.amount).toFixed(2) : ""
      }
      field="amount"
      header="Amount"
      style={{ width: "10em" }}
    />

但我没有得到任何结果。请帮忙,我是新来的反应

【问题讨论】:

    标签: javascript reactjs decimalformat


    【解决方案1】:
    <Column
      field={(object) =>
        object.amount !== null ? (Math.round(object.amount * 100) / 100).toFixed(2): ""
      }
      field="amount"
      header="Amount"
      style={{ width: "10em" }}
    />
    

    假设你在 object.anount 中有你的价值

    【讨论】:

    • 不适合我
    • 你能控制object.amount的值吗?
    猜你喜欢
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 2016-10-04
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多