【问题标题】:Limit the length of number by rounding it通过四舍五入限制数字的长度
【发布时间】:2022-06-15 03:59:58
【问题描述】:

我希望我的号码最大长度为 4 位。 例如:

input 1.234567 should output 1.236
input 12.34567 should output 12.34
input 123.4567 should output 123.5

【问题讨论】:

  • 您的问题是什么? “应该输出”是什么意思?
  • 123456 或 0.000000123456 怎么样?
  • 我没有看到您期望的输出的任何押韵或原因
  • 为什么第一个是1.236?不应该是1.234 还是1.235(取决于你是要向下舍入还是最接近)?
  • var number = 1.234567; console.log(number.toFixed(3)); 虽然不会是 1.236,但最接近的四舍五入数字是 1.235

标签: javascript


猜你喜欢
  • 2015-11-12
  • 1970-01-01
  • 2018-08-03
  • 1970-01-01
  • 2020-10-22
  • 1970-01-01
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
相关资源
最近更新 更多