-
formatNumber
(value, formatOptions)
{String}
將
Number
值格式化為當前語言環境中的字符串。在內部
formatNumber
為當前語言環境創建 Intl formatter 實例。格式化程序使用它們的options
作為緩存鍵進行緩存。重複使用相同的options
對象以獲得最佳性能。參數:
類型 說明 value Number要格式化的數字。
formatOptions Intl.NumberFormatOptions可選的 數字格式選項。
返回:
類型 說明 String 輸入數字的格式化字符串。 例子:
// Formats a number with a fixed number of places using a digit separator const numberFormatIntlOptions = intl.convertNumberFormatToIntlOptions({ places: 2, digitSeparator: true }); const number = 123456.789; const formattedNumber = intl.formatNumber(123456.789, numberFormatIntlOptions); console.log(formattedNumber); // In US English locale: 123,456.79
// Formats a number as currency, in Euros const amount = 14; const formattedNumber = intl.formatNumber(amount, { style: "currency", currency: "EUR", currencyDisplay: "symbol" }); console.log(formattedNumber); // In for US English locale: €14.00
// Formats a number as percentage const growth = 0.5; const formattedNumber = intl.formatNumber(growth, { style: "percent" }); console.log(formattedNumber); // In for US English locale: 50%
基本信息
以下是所在類或對象的基本信息。
AMD:
require(["esri/intl"], (intl) => { /* code goes here */ });
ESM:
import * as intl from "@arcgis/core/intl";
對象:
esri/intl
自從:用於 JavaScript 4.12 的 ArcGIS API
用法說明
intl.formatNumber
函數(或屬性)的定義如下:
相關用法
- JavaScript ArcGIS intl.formatDate用法及代碼示例
- JavaScript ArcGIS intl.fetchMessageBundle用法及代碼示例
- JavaScript ArcGIS intl.convertDateFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.normalizeMessageBundleLocale用法及代碼示例
- JavaScript ArcGIS intl.SubstituteOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteDateTimeFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.SubstituteNumberFormatOptions用法及代碼示例
- JavaScript ArcGIS intl.convertNumberFormatToIntlOptions用法及代碼示例
- JavaScript ArcGIS intl.createJSONLoader用法及代碼示例
- JavaScript ArcGIS intl.registerMessageBundleLoader用法及代碼示例
- JavaScript ArcGIS intl.setLocale用法及代碼示例
- JavaScript ArcGIS intl.MessageBundleLoader用法及代碼示例
- JavaScript ArcGIS intl.onLocaleChange用法及代碼示例
- JavaScript ArcGIS intl.substitute用法及代碼示例
- JavaScript includes()用法及代碼示例
- JavaScript isFinite()用法及代碼示例
- JavaScript isNaN()用法及代碼示例
- JavaScript ArcGIS imageService.getSamples用法及代碼示例
- JavaScript ArcGIS SceneView double-click事件用法及代碼示例
- JavaScript ArcGIS geometryEngineAsync.overlaps用法及代碼示例
- JavaScript ArcGIS Expand.when用法及代碼示例
- JavaScript ArcGIS Sublayer.JoinTableDataSource用法及代碼示例
- JavaScript ArcGIS FillSymbol3DLayer.outline用法及代碼示例
- JavaScript ArcGIS Ground.loadAll用法及代碼示例
- JavaScript Object valueOf()用法及代碼示例
注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 intl.formatNumber。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。