mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibJS: Use decimal compact patterns for currency style sub-patterns
When formatting a currency style pattern with compact notation, we were (trying to) doubly insert the currency symbol into the formatted string. We would first look up the currency pattern in GetNumberFormatPattern (for the en locale, this is "¤#,##0.00", which our generator transforms to "{currency}{number}"). When we hit the "{number}" field, NumberFormat will do a second lookup for the compact pattern to use for the number being formatted. By using the currency compact patterns, we receive a second pattern that also has the currency symbol (for the en locale, if formatting the number 1000, this is "¤0K", which our generator transforms to "{currency}{number}{compactIdentifier:0}". This second lookup is not supposed to have currency symbols (or any other symbols), thus we hit a VERIFY_NOT_REACHED(). Instead, we are meant to use the decimal compact pattern, and allow the currency symbol to be handled by only the outer currency pattern.
This commit is contained in:
parent
e3f693ca7c
commit
ca0d926036
2 changed files with 144 additions and 8 deletions
|
@ -1634,15 +1634,11 @@ int compute_exponent_for_magnitude(NumberFormat& number_format, int magnitude)
|
|||
|
||||
// b. Let exponent be an implementation- and locale-dependent (ILD) integer by which to scale a number of the given magnitude in compact notation for the current locale.
|
||||
// c. Return exponent.
|
||||
Vector<::Locale::NumberFormat> format_rules;
|
||||
|
||||
if (number_format.style() == NumberFormat::Style::Currency)
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::CurrencyShort);
|
||||
else if (number_format.compact_display() == NumberFormat::CompactDisplay::Long)
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalLong);
|
||||
else
|
||||
format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), ::Locale::CompactNumberFormatType::DecimalShort);
|
||||
auto compact_format_type = number_format.compact_display() == NumberFormat::CompactDisplay::Short || number_format.style() == NumberFormat::Style::Currency
|
||||
? ::Locale::CompactNumberFormatType::DecimalShort
|
||||
: ::Locale::CompactNumberFormatType::DecimalLong;
|
||||
|
||||
auto format_rules = ::Locale::get_compact_number_system_formats(number_format.data_locale(), number_format.numbering_system(), compact_format_type);
|
||||
::Locale::NumberFormat const* best_number_format = nullptr;
|
||||
|
||||
for (auto const& format_rule : format_rules) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue