1 package org.exoplatform.services.workflow.format; 2 3 import java.text.DecimalFormat ; 4 import java.text.FieldPosition ; 5 import java.text.Format ; 6 import java.text.ParseException ; 7 import java.text.ParsePosition ; 8 9 10 public class DoubleFormat extends Format { 11 12 DecimalFormat decimalFormat = new DecimalFormat (); 13 14 public DoubleFormat() { 15 decimalFormat = new DecimalFormat ("0.####################################"); 16 } 17 18 public Object parseObject(String source, ParsePosition pos) { 19 Double result = null; 20 21 if ( source != null ) { 22 try { 23 result = new Double (decimalFormat.parse(source).doubleValue()); 24 pos.setErrorIndex(-1); 25 pos.setIndex(source.length()); 26 } 27 catch(ParseException e) { 28 pos.setErrorIndex(e.getErrorOffset()); 29 } 30 } 31 32 return result; 33 } 34 35 public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { 36 if ( obj != null ) { 37 toAppendTo.append(decimalFormat.format(obj)); 38 } 39 return toAppendTo; 40 } 41 42 } 43 | Popular Tags |