//----------------------------------------------------------------------------- var BUGNUMBER = 1289882; var summary = "Implement Intl.NumberFormat.prototype.formatToParts";
assertEq("formatToParts" in Intl.NumberFormat(), true);
// NOTE: Some of these tests exercise standard behavior (e.g. that format and // formatToParts expose the same formatted string). But much of this, // like the exact-formatted-string expectations, is technically // implementation-dependent. This is necessary as a practical matter to // properly test the conversion from ICU's nested-field exposure to // ECMA-402's sequential-parts exposure.
// Test behavior of a currency with code formatting. var usdCodeOptions =
{
style: "currency",
currency: "USD",
currencyDisplay: "code",
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}; var usDollarsCode = new Intl.NumberFormat("en-US", usdCodeOptions);
// ISO 4217 currency codes are formed from an ISO 3166-1 alpha-2 country code // followed by a third letter. ISO 3166 guarantees that no country code // starting with "X" will ever be assigned. Stepping carefully around a few // 4217-designated special "currencies", XQQ will never have a representation. // Thus, yes: this really is specified to work, as unrecognized or unsupported // codes pass into the string unmodified. var xqqCodeOptions =
{
style: "currency",
currency: "XQQ",
currencyDisplay: "code",
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}; var xqqMoneyCode = new Intl.NumberFormat("en-US", xqqCodeOptions);
// But if the implementation doesn't recognize the currency, the provided code // is used in place of a proper name, unmolested. var xqqNameOptions =
{
style: "currency",
currency: "XQQ",
currencyDisplay: "name",
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}; var xqqMoneyName = new Intl.NumberFormat("en-US", xqqNameOptions);
// Test some currencies with fractional components.
var usdNameFractionOptions =
{
style: "currency",
currency: "USD",
currencyDisplay: "name",
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}; var usdNameFractionFormatter = new Intl.NumberFormat("en-US", usdNameFractionOptions);
// The US national surplus (i.e. debt) as of October 18, 2016. (Replicating // data from a comment in builtin/Intl/NumberFormat.cpp.) var usNationalSurplus = -19766580028249.41;
var usDecimalOptions =
{
style: "decimal",
maximumFractionDigits: 7 // minimum defaults to 0
}; var usDecimalFormatter = new Intl.NumberFormat("en-US", usDecimalOptions);
var deDecimalOptions =
{
style: "decimal",
maximumFractionDigits: 7 // minimum defaults to 0
}; var deDecimalFormatter = new Intl.NumberFormat("de-DE", deDecimalOptions);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.