System.out.println("------case1------");BigDecimal bigDecimal = new BigDecimal(37.98);System.out.println(bigDecimal); //37.97999999999999687361196265555918216705322265625System.out.println(bigDecimal.intValue()); //37System.out.println("------case2------");int totalAmount = (int) (37.98 * 100); System.out.println(totalAmount); //3797System.out.println("------case3------");totalAmount = new BigDecimal(37.98 * 100).intValue();System.out.println(totalAmount); //3797System.out.println("------case4------");System.out.println(bigDecimal.movePointRight(2)); //3797.999999999999687361196265555918216705322265625System.out.println(bigDecimal.movePointRight(2).intValue()); //3797System.out.println("------case5------");System.out.println(new BigDecimal(37).intValueExact()); //没有异常,没有小数点被截取 37//System.out.println(bigDecimal.intValueExact()); //存在异常,小数点精度丢失System.out.println("------case6------");System.out.println(bigDecimal.multiply(new BigDecimal(100))); //3797.99999999999968736119626555591821670532226562500System.out.println(bigDecimal.multiply(new BigDecimal(100)).intValue()); //3797//正确处理System.out.println("------case7------");System.out.println(new BigDecimal(37.9899).setScale(2, BigDecimal.ROUND_HALF_UP)); //保留两位小数,后面小数上取整 37.99System.out.println(bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue()); //3798System.out.println(Math.ceil(37.98 * 100)); //37.98 * 100 = 3797.9999999999995System.out.println((int) Math.ceil(37.98 * 100)); //3798
------case1------
37.97999999999999687361196265555918216705322265625 37 ------case2------ 3797 ------case3------ 3797 ------case4------ 3797.999999999999687361196265555918216705322265625 3797 ------case5------ 37 ------case6------ 3797.99999999999968736119626555591821670532226562500 3797 ------case7------ 37.99 3798 3797.9999999999995 3798.0 3798