博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BigDecimal用double初始化并设置精确度的问题
阅读量:5759 次
发布时间:2019-06-18

本文共 5504 字,大约阅读时间需要 18 分钟。

  hot3.png

System.out.println(new BigDecimal(9.99)); // 9.9900000000000002131628207280300557613372802734375System.out.println(new BigDecimal(9.99).setScale(2, BigDecimal.ROUND_CEILING)); // 10.00System.out.println(new BigDecimal(9.55)); // 9.550000000000000710542735760100185871124267578125System.out.println(new BigDecimal(9.55).setScale(2, BigDecimal.ROUND_CEILING)); // 9.56System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_CEILING)); // 9.10System.out.println(new BigDecimal(-9.44)); // -9.4399999999999995026200849679298698902130126953125System.out.println(new BigDecimal(-9.44).setScale(2, BigDecimal.ROUND_CEILING)); // -9.43System.out.println(new BigDecimal(-9.11)); // -9.1099999999999994315658113919198513031005859375System.out.println(new BigDecimal(-9.11).setScale(2, BigDecimal.ROUND_CEILING)); // -9.10System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_CEILING)); // -9.09System.out.println(new BigDecimal(9.44)); // 9.4399999999999995026200849679298698902130126953125System.out.println(new BigDecimal(9.44).setScale(2, BigDecimal.ROUND_DOWN)); // 9.43System.out.println(new BigDecimal(9.11)); // 9.1099999999999994315658113919198513031005859375System.out.println(new BigDecimal(9.11).setScale(2, BigDecimal.ROUND_DOWN)); // 9.10System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_DOWN)); // 9.09System.out.println(new BigDecimal(-9.44)); // -9.4399999999999995026200849679298698902130126953125System.out.println(new BigDecimal(-9.44).setScale(2, BigDecimal.ROUND_DOWN)); // -9.43System.out.println(new BigDecimal(-9.11)); // -9.1099999999999994315658113919198513031005859375System.out.println(new BigDecimal(-9.11).setScale(2, BigDecimal.ROUND_DOWN)); // -9.10System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_DOWN)); // -9.09System.out.println(new BigDecimal(9.44)); // 9.4399999999999995026200849679298698902130126953125System.out.println(new BigDecimal(9.44).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.43System.out.println(new BigDecimal(9.11)); // 9.1099999999999994315658113919198513031005859375System.out.println(new BigDecimal(9.11).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.10System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_FLOOR)); // 9.09System.out.println(new BigDecimal(-9.99)); // -9.9900000000000002131628207280300557613372802734375System.out.println(new BigDecimal(-9.99).setScale(2, BigDecimal.ROUND_FLOOR)); // -10.00System.out.println(new BigDecimal(-9.55)); // -9.550000000000000710542735760100185871124267578125System.out.println(new BigDecimal(-9.55).setScale(2, BigDecimal.ROUND_FLOOR)); // -9.56System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_FLOOR)); // -9.10System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_DOWN)); // 9.10System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_DOWN)); // -9.10System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_EVEN)); // 9.10System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_EVEN)); // -9.10System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_HALF_UP)); // 9.10System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_HALF_UP)); // -9.10System.out.println(new BigDecimal(9.99)); // 9.9900000000000002131628207280300557613372802734375System.out.println(new BigDecimal(9.99).setScale(2, BigDecimal.ROUND_UP)); // 10.00System.out.println(new BigDecimal(9.55)); // 9.550000000000000710542735760100185871124267578125System.out.println(new BigDecimal(9.55).setScale(2, BigDecimal.ROUND_UP)); // 9.56System.out.println(new BigDecimal(9.1)); // 9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(9.1).setScale(2, BigDecimal.ROUND_UP)); // 9.10System.out.println(new BigDecimal(-9.99)); // -9.9900000000000002131628207280300557613372802734375System.out.println(new BigDecimal(-9.99).setScale(2, BigDecimal.ROUND_UP)); // -10.00System.out.println(new BigDecimal(-9.55)); // -9.550000000000000710542735760100185871124267578125System.out.println(new BigDecimal(-9.55).setScale(2, BigDecimal.ROUND_UP)); // -9.56System.out.println(new BigDecimal(-9.1)); // -9.0999999999999996447286321199499070644378662109375System.out.println(new BigDecimal(-9.1).setScale(2, BigDecimal.ROUND_UP)); // -9.10

转载于:https://my.oschina.net/morven/blog/533021

你可能感兴趣的文章
剑指实体零售,亚马逊的网络品牌进化之路
查看>>
Exchange Server 2010部署(四)安装Exchange 2010邮箱角色服务器
查看>>
《统一沟通-微软-技巧》-14-Exchange 2010 With SP1 OWA Integration
查看>>
DB2 错误信息(按sqlcode排序)
查看>>
微软私有云分享(R2)2-服务模板的变量
查看>>
理解流量控制(整形和监管行为)
查看>>
如何下载DELL服务器VMware ESXi镜像
查看>>
老鸟运维的下场
查看>>
不懂技术的人请不要对懂技术的人说这很容易
查看>>
AWS安全审计相关参考
查看>>
React.js VS Vue.js
查看>>
管理数据和并发处理
查看>>
【原创】MySQL 5.6 置换分区体验
查看>>
烂泥:KVM虚拟机随KVM服务器的启动而启动
查看>>
基于Maven管理的JavaWeb项目目录结构参考
查看>>
SCOM2012部署系列之九:部署审核收集报告(ACSReporting)
查看>>
浅析ARM公司在物联网领域的战略布局
查看>>
MariaDB10 多源复制搭建演示
查看>>
Lync Server外部访问系列PART2:部署边缘
查看>>
python字符串按固定长度拆分
查看>>