本帖最后由 黑马刘涛 于 2012-7-17 11:35 编辑
- public class Hello {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- double Num = 1234.5678;
- //long Num2 = (long)Math.floor(Num);
- double Num4 = (int)(Num*100);
- double Num3 = (double)((int)(Num*100))/100;// double 类型数值与整型数值相除,会保留小数
- System.out.println(Num4);
- System.out.println(Num3);
- }
- }
复制代码 double Num3 = ((int)(Num*100))/100; //两个整数相除,会发生什么?比如3/2 = 1,((int)(Num*100))/100 = 123456/100 =1234,然后结果转为double类型,Num3 = 1234.0
|