Debian Codegraph @

src/com/jidesoft/converter/BigDecimalConverter.java

raw
1 package com.jidesoft.converter;
2
3 import java.math.BigDecimal;
4 import java.text.DecimalFormat;
5 import java.text.NumberFormat;
6
7 /**
8 * Converter for BigDecimal.
9 */
10 public class BigDecimalConverter extends NumberFormatConverter {
11
12 public BigDecimalConverter() {
13 super(new DecimalFormat("#,##0.00"));
14 }
15
16 public BigDecimalConverter(NumberFormat format) {
17 super(format);
18 }
19
20 @Override
21 public Object fromString(String string, ConverterContext context) {
22 Object value = super.fromString(string, context);
23 return new BigDecimal("" + value);
24 }
25
26 @Override
27 public String toString(Object obj, ConverterContext convertercontext) {
28 if (obj instanceof BigDecimal) {
29 BigDecimal decimal = (BigDecimal) obj;
30 if (decimal.doubleValue() == Double.NaN)
31 return "";
32 return super.toString(decimal, convertercontext);
33 }
34 return ""; // null or not an instance of BigDecimal
35 }
36 }