Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.garciapl.test;
- import org.springframework.format.Formatter;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.text.ParseException;
- import java.util.Locale;
- public class CurrencyLocaleBigDecimalFormatter implements Formatter<BigDecimal> {
- @Override
- public BigDecimal parse(String text, Locale locale) throws ParseException {
- DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
- format.applyPattern("#,##0.00");
- format.setParseBigDecimal(true);
- format.setGroupingUsed(true);
- return (BigDecimal) format.parse(text);
- }
- @Override
- public String print(BigDecimal object, Locale locale) {
- DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(locale);
- format.applyPattern("#,##0.00");
- format.setParseBigDecimal(true);
- format.setGroupingUsed(false);
- return format.format(object);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment