概述Intl.NumberFormat 提供对数字的本地化格式,支持货币与单位展示、紧凑表示(如 1.2K)、分组与小数控制。适用于多语言站点与报表。示例const nfCurrency = new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY', currencyDisplay: 'symbol' }) console.log(nfCurrency.format(1234.56)) const nfUnit = new Intl.NumberFormat('zh-CN', { style: 'unit', unit: 'kilometer', unitDisplay: 'short' }) console.log(nfUnit.format(3.5)) const nfCompact = new Intl.NumberFormat('zh-CN', { notation: 'compact', maximumFractionDigits: 1 }) console.log(nfCompact.format(1200)) // ≈ 1.2K 工程建议货币与单位:按地区使用正确货币代码与单位;避免硬编码符号。性能:缓存格式器实例;避免在渲染循环中新建。兼容:不支持选项时回退到自定义格式化;保持语义一致。参考与验证MDN Intl.NumberFormat 文档:https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormatECMA-402 规范:https://tc39.es/ecma402/#numberformat-objects

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部