1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.web.format; |
17 | |
|
18 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
19 | |
import org.kuali.rice.core.api.util.type.KualiDecimal; |
20 | |
import org.kuali.rice.core.api.util.type.KualiInteger; |
21 | |
|
22 | |
import java.text.NumberFormat; |
23 | |
|
24 | 0 | public class KualiIntegerCurrencyFormatter extends CurrencyFormatter { |
25 | |
|
26 | |
private static final long serialVersionUID = 1022217841658237940L; |
27 | |
|
28 | |
protected Object convertToObject(String target) { |
29 | 0 | KualiDecimal value = (KualiDecimal) (super.convertToObject(target)); |
30 | 0 | return new KualiInteger(value.longValue()); |
31 | |
} |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public Object format(Object obj) { |
37 | 0 | if (obj == null) |
38 | 0 | return null; |
39 | |
|
40 | 0 | NumberFormat formatter = NumberFormat.getNumberInstance(); |
41 | 0 | String string = null; |
42 | |
|
43 | |
try { |
44 | 0 | KualiInteger number = (KualiInteger) obj; |
45 | 0 | string = formatter.format(number.doubleValue()); |
46 | |
} |
47 | 0 | catch (IllegalArgumentException e) { |
48 | 0 | throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e); |
49 | |
} |
50 | 0 | catch (ClassCastException e) { |
51 | 0 | throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e); |
52 | 0 | } |
53 | |
|
54 | 0 | return showSymbol() ? string : removeSymbol(string); |
55 | |
} |
56 | |
} |