Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,8 @@ protected CharSequence safeApply(final Object value, final Options options) {

String roundingMode = options.hash("roundingMode");
if (roundingMode != null) {
numberFormat.setRoundingMode(RoundingMode.valueOf(roundingMode.toUpperCase().trim()));
numberFormat.setRoundingMode(
RoundingMode.valueOf(roundingMode.toUpperCase(Locale.ROOT).trim()));
}

return numberFormat.format(number);
Expand All @@ -678,7 +679,7 @@ private NumberFormat build(final Options options) {
final String format = getFormatArgument(options);
final Locale locale = getLocaleArgument(options);
try {
NumberStyle style = NumberStyle.valueOf(format);
NumberStyle style = NumberStyle.valueOf(format.toUpperCase(Locale.ROOT).trim());
return style.numberFormat(locale);
} catch (IllegalArgumentException ex) {
return new DecimalFormat(format, new DecimalFormatSymbols(locale));
Expand All @@ -690,7 +691,7 @@ private String getFormatArgument(final Options options) {
if (stringifiedFormat == null || stringifiedFormat.isBlank()) {
return NumberStyle.DEFAULT.name();
}
return stringifiedFormat.toUpperCase().trim();
return stringifiedFormat;
}

private Locale getLocaleArgument(final Options options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ public void pattern() throws IOException {
shouldCompileTo("{{numberFormat this \"" + pattern + "\"}}", number, expected);
}

@Test
public void patternWithLiteralText() throws IOException {
Number number = Math.PI;
String pattern = "#,##0.00 'items'";
String expected =
new DecimalFormat(pattern, new DecimalFormatSymbols(Locale.getDefault())).format(number);
shouldCompileTo("{{numberFormat this \"" + pattern + "\"}}", number, expected);
}

@Test
public void namesDoNotDependOnDefaultLocale() throws IOException {
Locale defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
try {
Number number = Math.PI;
String expected = NumberFormat.getIntegerInstance(Locale.US).format(number);
shouldCompileTo("{{numberFormat this \"integer\" \"en_US\"}}", number, expected);
shouldCompileTo(
"{{numberFormat this \"0.0\" \"en_US\" roundingMode=\"ceiling\"}}", number, "3.2");
} finally {
Locale.setDefault(defaultLocale);
}
}

@Test
public void frLocale() throws IOException {
Number number = Math.PI;
Expand Down