限制小數(shù)點(diǎn)后面的位數(shù)
float aa=(float)26/7;
例如取2位小數(shù)
System.out.println(aa);
方法一:DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(aa));
方法二:System.out.println(Math.round(aa*100)/100.00);
例如取5位小數(shù)
方法一: DecimalFormat df = new DecimalFormat("0.00000");
System.out.println(df.format(aa));
方法二:System.out.println(Math.round(aa*100000)/100000.00);
例如取2位小數(shù)
System.out.println(aa);
方法一:DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(aa));
方法二:System.out.println(Math.round(aa*100)/100.00);
例如取5位小數(shù)
方法一: DecimalFormat df = new DecimalFormat("0.00000");
System.out.println(df.format(aa));
方法二:System.out.println(Math.round(aa*100000)/100000.00);
posted on 2007-12-13 19:54 龔椿深 閱讀(1124) 評(píng)論(0) 編輯 收藏