class="java" name="code">package com.my.util; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.List; public class FormateUtil { private static FormateUtil instance; public static final NumberFormat MONEY_FORMATE = new DecimalFormat("##0.0000"); public static final NumberFormat MONEY_FORMATE_LONG = new DecimalFormat("##0"); public static FormateUtil getInstance(){ if(instance==null){ instance = new FormateUtil(); } return instance; } public String formateDouble(Double value){ return this.formateDouble(value, ""); } public String formateDouble(Double value,String defaultValue){ if(value==null){ return defaultValue; }else{ return MONEY_FORMATE.format(value); } } public String formateDouble(Double value,String defaultValue,NumberFormat format){ if(value==null){ return defaultValue; }else{ return format.format(value); } } }
?