问题库 JavaScript / TypeScript how-to

JavaScript 如何格式化数字

快速答案

用 Intl.NumberFormat 处理千分位、货币和本地化格式。

js
const text = new Intl.NumberFormat('zh-CN').format(1234567.89);

使用要点

  • 先确认输入单位、时区和本地化格式,尤其是秒级时间戳与毫秒级时间戳。
  • 展示给用户的文本可以本地化,存储和接口传输仍建议使用明确格式。

相关内容