I have a screen where I work with jQuery Mask monetary value masks, when the user performs the submit form value returned to my controller is Ex :. 1.340,34.
The Bean attribute that bind bind is a BigDecimal . Soon I had to create a CustomNumberEditor and register it in an @InitBinder as shown below:@InitBinder
public void initBigDecimalBinder(WebDataBinder binder) throws Exception {
DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setGroupingSeparator('.');
dfs.setDecimalSeparator(',');
df.setDecimalFormatSymbols(dfs);
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, df, true));
}
The biggest problem is that the values do not look right, that is, the example number above is 1340 in the database, the right one being 1,340.34. >
How can I perform such a conversion correctly?