public class Test{
public static void main(String[] args) throws Exception{
/*DecimalFormat参数,如果是0则会显示0,如果是#怎不显示0*/
DecimalFormat df = new DecimalFormat("0.00"); System.out.println(df.format(1231213)); //输出:1231213.00 DecimalFormat df_2 = new DecimalFormat("#.##"); System.out.println(df_2.format(1231213)); //输出:1231213 }}
java.text.DecimalFormat API
- Symbol Location Localized? Meaning
- 0 Number Yes Digit
- # Number Yes Digit, zero shows as absent