1 package org.javabb.infra; 2 3 import java.text.DecimalFormat ; 4 import java.text.DecimalFormatSymbols ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 24 25 30 public class DigitFormat { 31 32 protected static Log log = LogFactory.getLog(DigitFormat.class); 33 34 private static DecimalFormat currencyFormat() { 35 DecimalFormat dec = new DecimalFormat ( 36 "#,###"); 37 DecimalFormatSymbols decDef = new DecimalFormatSymbols (); 38 decDef.setZeroDigit('0'); 39 decDef.setDecimalSeparator(','); 40 decDef.setMonetaryDecimalSeparator(','); 41 decDef.setDigit('#'); 42 decDef.setGroupingSeparator('.'); 43 dec.setDecimalFormatSymbols(decDef); 44 return dec; 45 } 46 47 52 public static String parserValue(String paramValue) { 53 String valor = currencyFormat().format(new Double (paramValue)); 54 String tmpVlr = valor; 55 if(valor.length() > 4){ 56 tmpVlr = valor.substring(valor.length() -4, valor.length()); 57 if(tmpVlr.equals("0000")){ 58 tmpVlr = valor.substring(0, valor.length()-4); 59 } else { 60 tmpVlr = valor; 61 } 62 } 63 return tmpVlr; 64 } 65 66 public static void main(String [] args){ 67 System.out.println(DigitFormat.parserValue("1.5435555E7")); 68 } 69 70 } | Popular Tags |