概述
为什么80%的码农都做不了架构师?>>>
System.out.println(new BigDecimal(9.99)); // 9.9900000000000002131628207280300557613372802734375
System.out.println(new BigDecimal(9.99).setScale(2, BigDecimal.ROUND_CEILING)); // 10.00
System.out.println(new BigDecimal(9.55)); // 9.550000000000000710542735760100185871124267578125
System.out.println(new BigDecimal(9.55).setScale(2, BigDecimal.ROUND_CEILING)); // 9.56
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_CEILING)); // 9.10
System.out.println(new BigDecimal(-9.44)); // -9.4399999999999995026200849679298698902130126953125
System.out.println(new BigDecimal(-9.44).setScale(2, BigDecimal.ROUND_CEILING)); // -9.43
System.out.println(new BigDecimal(-9.11)); // -9.1099999999999994315658113919198513031005859375
System.out.println(new BigDecimal(-9.11).setScale(2, BigDecimal.ROUND_CEILING)); // -9.10
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_CEILING)); // -9.09
System.out.println(new BigDecimal(9.44)); // 9.4399999999999995026200849679298698902130126953125
System.out.println(new BigDecimal(9.44).setScale(2, BigDecimal.ROUND_DOWN)); // 9.43
System.out.println(new BigDecimal(9.11)); // 9.1099999999999994315658113919198513031005859375
System.out.println(new BigDecimal(9.11).setScale(2, BigDecimal.ROUND_DOWN)); // 9.10
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_DOWN)); // 9.09
System.out.println(new BigDecimal(-9.44)); // -9.4399999999999995026200849679298698902130126953125
System.out.println(new BigDecimal(-9.44).setScale(2, BigDecimal.ROUND_DOWN)); // -9.43
System.out.println(new BigDecimal(-9.11)); // -9.1099999999999994315658113919198513031005859375
System.out.println(new BigDecimal(-9.11).setScale(2, BigDecimal.ROUND_DOWN)); // -9.10
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_DOWN)); // -9.09
System.out.println(new BigDecimal(9.44)); // 9.4399999999999995026200849679298698902130126953125
System.out.println(new BigDecimal(9.44).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.43
System.out.println(new BigDecimal(9.11)); // 9.1099999999999994315658113919198513031005859375
System.out.println(new BigDecimal(9.11).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.10
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.09
System.out.println(new BigDecimal(-9.99)); // -9.9900000000000002131628207280300557613372802734375
System.out.println(new BigDecimal(-9.99).setScale(2, BigDecimal.ROUND_FLOOR)); // -10.00
System.out.println(new BigDecimal(-9.55)); // -9.550000000000000710542735760100185871124267578125
System.out.println(new BigDecimal(-9.55).setScale(2, BigDecimal.ROUND_FLOOR)); // -9.56
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_FLOOR)); // -9.10
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_DOWN)); // 9.10
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_DOWN)); // -9.10
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_EVEN)); // 9.10
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_EVEN)); // -9.10
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_UP)); // 9.10
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_UP)); // -9.10
System.out.println(new BigDecimal(9.99)); // 9.9900000000000002131628207280300557613372802734375
System.out.println(new BigDecimal(9.99).setScale(2, BigDecimal.ROUND_UP)); // 10.00
System.out.println(new BigDecimal(9.55)); // 9.550000000000000710542735760100185871124267578125
System.out.println(new BigDecimal(9.55).setScale(2, BigDecimal.ROUND_UP)); // 9.56
System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_UP)); // 9.10
System.out.println(new BigDecimal(-9.99)); // -9.9900000000000002131628207280300557613372802734375
System.out.println(new BigDecimal(-9.99).setScale(2, BigDecimal.ROUND_UP)); // -10.00
System.out.println(new BigDecimal(-9.55)); // -9.550000000000000710542735760100185871124267578125
System.out.println(new BigDecimal(-9.55).setScale(2, BigDecimal.ROUND_UP)); // -9.56
System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375
System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_UP)); // -9.10
转载于:https://my.oschina.net/morven/blog/533021
最后
以上就是聪明滑板为你收集整理的BigDecimal用double初始化并设置精确度的问题的全部内容,希望文章能够帮你解决BigDecimal用double初始化并设置精确度的问题所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复