Tool Hub

數字格式化

預覽 Intl.NumberFormat 的貨幣、小數、百分比與單位輸出

預覽 Intl.NumberFormat 選項組合的結果。比較同一數字在不同 locale、樣式和位數設定下的顯示,可直接複製程式碼使用。

覆寫

1,234,567.89

代碼
new Intl.NumberFormat("en-US", {
  "style": "decimal",
  "minimumFractionDigits": 0,
  "maximumFractionDigits": 2
}).format(number)

使用方法

  1. Enter a number in the number field。
  2. Choose a locale from the dropdown (e.g. en-US, de-DE) or type any BCP 47 tag in the override field。
  3. Select a style: decimal, currency, percent, or unit。
  4. For currency style pick a currency code; for unit style pick a unit such as kilometer-per-hour。
  5. Adjust min and max fraction digits to control decimal precision。

範例

  • Entering 1234567.89 with locale de-DE and style decimal produces 1.234.567,89。
  • Entering 0.0523 with locale en-US, style percent, and 1 max fraction digit produces 5.2%。

生產環境使用前請驗證輸出。無擔保 — 參見 條款.