Last active
March 27, 2020 12:19
-
-
Save mahozad/3ca3bc8f81d045e63bbe268d760a60d3 to your computer and use it in GitHub Desktop.
The fix for the bug in NumberUtils class in Thymeleaf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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