format Property (Intl.NumberFormat)

Returns a function that formats a locale-specific number by using the specified number formatter settings.

numberFormatObj.format

numberFormatObj

Required. The name of the NumberFormat object to use as a formatter.

The function returned by the format property takes a single argument, value, and returns a string that represents the localized number by using the options specified in the NumberFormat object. If value is not provided, the function returns NaN (not a number).

The following example uses a NumberFormat object to create a localized number.

var nf = new Intl.NumberFormat(["en-US"], {
    style: "currency",
    currency: "CNY",
    currencyDisplay: "symbol",
    maximumFractionDigit: 1
})

if (console && console.log) {
    console.log(nf.format(100)); // "¥100.00"
}

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information. Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

Show:
© 2014 Microsoft