double 转为long类型

System.out.println(new Double(234314.999999999).longValue());//234314
  System.out.println(new Double(234314.9999999999).longValue());//234314
  System.out.println(new Double(234314.99999999999).longValue());//234315
  System.out.println(new Double(234314.999999999999).longValue());//234315 

 

  System.out.println((long)234314.999999999);//234314
  System.out.println((long)234314.9999999999);//234314
  System.out.println((long)234314.99999999999);//234315
  System.out.println((long)234314.999999999999);//234315

 

double转long时,小数位数不同,得到的结果可能不一样

正常时直接舍去小数位,小数位大于等于11位时可能会进位

posted @ 2020-01-17 17:42  CoderRdf  阅读(8355)  评论(0)    收藏  举报