1.
public class DecimalFormatterTest { public static void main(String[] args) { //DecimalFormat df = new DecimalFormat("0.00#"); //两个构造器 DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.applyPattern(".###"); System.out.println(decimalFormat.format(23.112));//23.112 System.out.println(decimalFormat.format(0.112));//.112 decimalFormat.applyPattern("0.00#");//推荐 System.out.println(decimalFormat.format(23.112));//23.112 System.out.println(decimalFormat.format(0.112));//0.112 decimalFormat.applyPattern("0.00%");//推荐 System.out.println(decimalFormat.format(23.112));//2311.20% System.out.println(decimalFormat.format(0.112));//11.20% System.out.println(decimalFormat.format(0.2345));//23.45% decimalFormat.applyPattern(".##%"); System.out.println(decimalFormat.format(23.112));//2311.2% System.out.println(decimalFormat.format(0.112));//11.2% System.out.println(decimalFormat.format(0.2345));//23.45% } }
时间: 2024-10-06 19:21:34