java DecimalFormat

时间:2022-07-29 01:05:00

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

  1. Symbol    Location   Localized?  Meaning
  2. 0              Number    Yes            Digit
  3. #             Number     Yes            Digit, zero shows as absent