【问题标题】:Rounding to two significant digits after the dot (javascript)在点后四舍五入到两位有效数字(javascript)
【发布时间】:2022-06-15 04:28:15
【问题描述】:

帮助简洁地用 Javascript 编写代码。 已检查的数字(9 个字符;0

12.345678 -> 12.35
0.123456 -> 0.12
0.023456 -> 0.023
0.003456 -> 0.0035
0.000456 -> 0.00046

【问题讨论】:

标签: javascript rounding


【解决方案1】:

console.log(2.23452346.toFixed(2))

你只想要 toFixed 函数

如果您不想要字符串输出,请使用:

Number(2.2351.toFixed(2))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2013-03-23
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多