Access数据库中round方法四舍五入问题
来源:互联网 发布:js的相对定位 编辑:程序博客网 时间:2024/04/20 21:08
java中拼接的access数据库的sql中使用round方法进行四舍五入有时候遇到5会有问题,确切的说是四舍六入,5不一定。
后来看到有的用format方法代替round方法:如:
String sql = "select format(Zcf,'Fixed') as cs from table";
执行这段sql的时候java会报异常:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'i'at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:826)at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:634)at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:605)at com.hxtt.global.ao.a(Unknown Source)at com.hxtt.global.ao.a(Unknown Source)
这里就不全写了。
后来找到一种解决办法:还是用round方法:
地址:https://www.techonthenet.com/access/functions/numeric/round.php
在文章的最后一部分讲到了这一块的问题:
在 round方法的参数里加上0.0001,这样就能保证逢五必进一。
附原文(英文):(大概意思一目了然就不翻译了)
Question: I read your explanation of the Round function using the round-to-even logic. However, I really need to round some values in the traditional sense (where 5 always rounds up). How can I do this?
Answer: You could always use the following logic:
If you wanted to round 12.65 to 1 decimal place in the traditional sense (where 12.65 rounded to 1 decimal place is 12.7, instead of 12.6), try adding 0.000001 to your number before applying the Round function:
Round(12.45+0.000001,1)
By adding the 0.000001, the expression that you are rounding will end in 1, instead of 5...causing the Round function to round in the traditional way.
And the 0.000001 does not significantly affect the value of your expression so you shouldn't introduce any calculation errors.
- Access数据库中round方法四舍五入问题
- 解决access中round函数不能正确四舍五入的问题 (备忘)
- Access数据库中Round用法
- 四舍五入-round()方法
- oracle中round()四舍五入
- 关于python3中round()函数的四舍五入问题
- Math.round()的四舍五入问题
- Access数据库表四舍五入查询的实现
- Math.Round()方法的四舍五入(.NET)
- access中实现小数的四舍五入
- access中含四舍五入取值方法的查询sql语句
- Math.Round函数四舍五入的问题
- Round 四舍五入
- 四舍五入round()
- .Net中Math.Round与四舍五入
- C#中Math.Round()实现中国式四舍五入
- C#中Math.Round()实现中国式四舍五入
- C#中Math.Round()实现中国式四舍五入
- SQLSERVER存储过程、触发器、函数、游标等基本语法
- c# vs2010 directsound&…
- AVG2013 杀毒软件激活 …
- Flex 布局教程:语法篇
- python MySQLdb MySQL查…
- Access数据库中round方法四舍五入问题
- lua学习笔记——开发工具准备
- 来北京后最苦的日子已经开始了。。…
- 【原创】 linux-python-MySQL…
- java实现图片水平翻转
- 【原创】简单的python多线程队列
- 有些人,注定一辈子不会忘;有些人…
- 世人笑我太疯癫,我笑世人看不穿
- Eclipse远程调试Tomcat