Guest User

GarciaPL

a guest
Jan 23rd, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package pl.garciapl.test;
  2.  
  3. import org.springframework.format.Formatter;
  4.  
  5. import java.text.DecimalFormat;
  6. import java.text.NumberFormat;
  7. import java.text.ParseException;
  8. import java.util.Locale;
  9.  
  10. public class CurrencyLocaleLongFormatter implements Formatter<Long> {
  11.  
  12.     @Override
  13.     public Long parse(String text, Locale locale) throws ParseException {
  14.         DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
  15.         format.applyPattern("#,##0.00");
  16.         format.setParseBigDecimal(false);
  17.         format.setGroupingUsed(true);
  18.         return (Long) format.parse(text);
  19.     }
  20.  
  21.     @Override
  22.     public String print(Long object, Locale locale) {
  23.         DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(locale);
  24.         format.applyPattern("#,##0.00");
  25.         format.setParseBigDecimal(false);
  26.         format.setGroupingUsed(false);
  27.         return format.format(object);
  28.     }
  29. }
Add Comment
Please, Sign In to add comment