1function getFine(speed, amount) { 2 const formattedSpeed = new Intl.NumberFormat('en-US', { 3 style: 'unit', unit: 'mile-per-hour' 4 }).format(speed) 5 6 const formattedAmount = new Intl.NumberFormat('en-US', { 7 style: 'currency', currency: 'USD' 8 }).format(amount) 9 10 return `The driver drove ${formattedSpeed} and has to pay ${formattedAmount}` 11} 12 13console.log(getFine(130, 300))
本题为"单选题"
参考答案:
正确选项:B:The driver drove 130 mph and has to pay $300.00
通过方法 Intl.NumberFormat,可以格式化任意区域的数字值。我们对数字值 130 进行 mile-per-hour 作为 unit 的 en-US 区域 格式化,结果为 130 mph。对数字值 300 进行 USD 作为 currency 的 en-US 区域格式化,结果为 $300.00.
注意:
130 mph是带完整 ICU 数据的运行时(Node 14+、现代浏览器)下的结果。style: 'unit'的输出依赖运行时内置的 ICU 数据,个别环境可能输出130 mile-per-hour,甚至退化成130。需要精确控制写法时应显式指定unitDisplay:'short'→130 mph,'narrow'→130mph,'long'→130 miles per hour。
最近更新时间:2026-10-26

题库维护不易,您的支持就是我们最大的动力!