1 11 package com.ibm.icu.text; 12 13 import java.text.FieldPosition ; 14 import java.text.ParsePosition ; 15 16 import com.ibm.icu.util.CurrencyAmount; 17 import com.ibm.icu.util.ULocale; 18 19 32 class CurrencyFormat extends MeasureFormat { 33 static final long serialVersionUID = -931679363692504634L; 35 36 private NumberFormat fmt; 37 38 public CurrencyFormat(ULocale locale) { 39 fmt = NumberFormat.getCurrencyInstance(locale.toLocale()); 40 } 41 42 46 public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 47 try { 48 CurrencyAmount currency = (CurrencyAmount) obj; 49 fmt.setCurrency(currency.getCurrency()); 50 return fmt.format(currency.getNumber(), toAppendTo, pos); 51 } catch (ClassCastException e) { 52 throw new IllegalArgumentException ("Invalid type: " + obj.getClass().getName()); 53 } 54 } 55 56 60 public Object parseObject(String source, ParsePosition pos) { 61 return fmt.parseCurrency(source, pos); 62 } 63 } 64 | Popular Tags |