Skip to content

Instantly share code, notes, and snippets.

@mahozad
Last active March 27, 2020 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahozad/3ca3bc8f81d045e63bbe268d760a60d3 to your computer and use it in GitHub Desktop.
Save mahozad/3ca3bc8f81d045e63bbe268d760a60d3 to your computer and use it in GitHub Desktop.
The fix for the bug in NumberUtils class in Thymeleaf
private static DecimalFormatSymbols computeDecimalFormatSymbols(
final NumberPointType decimalPointType, final NumberPointType thousandsPointType, final Locale locale) {
Validate.notNull(decimalPointType, "Decimal point type cannot be null");
Validate.notNull(thousandsPointType, "Thousands point type cannot be null");
Validate.notNull(locale, "Locale cannot be null");
final DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
switch (decimalPointType) {
case POINT :
symbols.setDecimalSeparator('.');
break;
case COMMA :
symbols.setDecimalSeparator(',');
break;
case WHITESPACE :
symbols.setDecimalSeparator(' ');
break;
case DEFAULT :
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
symbols.setDecimalSeparator(dfs.getDecimalSeparator());
break;
case NONE :
// This should never happen
symbols.setDecimalSeparator('?');
break;
}
switch (thousandsPointType) {
case POINT :
symbols.setGroupingSeparator('.');
break;
case COMMA :
symbols.setGroupingSeparator(',');
break;
case WHITESPACE :
symbols.setGroupingSeparator(' ');
break;
case DEFAULT :
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale);
symbols.setGroupingSeparator(dfs.getGroupingSeparator());
break;
case NONE :
// This should never be shown
symbols.setGroupingSeparator('?');
break;
}
return symbols;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment