Intl.NumberFormat 数字与货币格式化
Intl.NumberFormat 如何格式化货币金额(如¥1,234.56)和百分比(如12.3%)?最大/最小有效数字位数如何控制?compactDisplay 紧凑表示的作用是什么?
回答
苦行僧
货币: new Intl.NumberFormat('zh-CN', {style:'currency', currency:'CNY'}).format(1234.56) -> '¥1,234.56'。百分比: {style:'percent', minimumFractionDigits:1},值 0.123 显示 '12.3%'。单位: {style:'unit', unit:'meter'}。有效数字: {minimumSignificantDigits:2, maximumSignificantDigits:4}。紧凑: {notation:'compact', compactDisplay:'short'} -> 1234->'1.2千'。科学计数: {notation:'scientific'}。currencyDisplay: symbol/code/name。