四舍五入
1 public class helloworld 2 { 3 public static void main(String[] args) 4 { 5 double a=4.561234; 6 System.out.println(Math.round(a));//四舍五入 7 System.out.println(Math.round(a*100)/100.0);//怎么取得小数点的后两位//先乘以100,乘出的结果会四舍五入掉,最后除以100.0就会把小数点还原到以前的位置上了 8 //注意:四舍五入出来的数是int类型 9 10 //上限与下限 11 double b=12.34; 12 System.out.println(Math.ceil(b));//上限 13 System.out.println(Math.floor(b));//下线 14 15 //定义了一个圆周率 16 System.out.println(Math.PI); 17 } 18 }

浙公网安备 33010602011771号