Oracle ceil 用于十进制数
当四舍五入到小数点后两位时,值 4.01132141 将四舍五入到 4.02,因为它超过了 4.01。
如何在 PL/SQL 中做到这一点?
When rounding up to 2 decimal places, the value 4.01132141 would be rounded to 4.02 because it exceeds 4.01.
How can you do this in PL/SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一种方法是执行 ceil(value*100)/100 ,但这似乎不太优雅。不确定是否有任何方法可以使
round
的行为符合您想要的方式。One way would be to do
ceil(value*100)/100
, but that seems inelegant. Not sure there's any way to makeround
behave the way you want.“向上取整”的函数是 CEIL,但它会生成一个整数。
“向下舍入”的函数是 FLOOR,但它也会生成一个整数。
“舍入最近的”函数是 ROUND,它允许您指定一个小数位数 (dp)。
请注意,CEIL 四舍五入为整数;要四舍五入到 2 dp,您必须乘以 100,使用 CEIL,然后除以 100。
要直接合理地获得答案,请使用:
这样做是有效的,因为对于 4.01132141 的示例数据,传递给 ROUND 的值是 4.01632 ,四舍五入为 2 dp 时,结果变为 4.02。例如,如果该值开始为 4.0593,则传递给 ROUND 的值将为 4.0643,根据需要舍入到 2 dp 后,该值将变为 4.06。
这里有一些棘手的地方:
The function to 'round up' is CEIL, but it generates an integer.
The function to 'round down' is FLOOR, but it too generates an integer.
The function to 'round nearest' is ROUND, and it allows you to specify a number of decimal places (dp).
Note that CEIL rounds to an integer; to round to 2 dp, you'd have to multiply by 100, use CEIL, and divide by 100.
To get the answer reasonably directly, use:
This works because, for the example data of 4.01132141, the value passed to ROUND is 4.01632, and when rounded to 2 dp, that becomes 4.02. If the value started as 4.0593, say, then the value passed to ROUND would be 4.0643, which when rounded to 2 dp becomes 4.06, as required.
There are a couple of tricky bits there:
我遇到了同样的问题并提出了以下声明,到目前为止效果很好。
I faced the same issue and came up with the following statement, it has worked fine so far.
从双选择 4.01132141、CEIL(4.01132141*100)/100
select 4.01132141, CEIL(4.01132141*100)/100 from dual
您可以在 PLSQL 中使用它进行舍入:
ROUND( UrNo+ (5 / POWER(10, 小数位数 + 1)) , 小数位数)
You can use this for Rounding up in PLSQL:
ROUND( UrNo+ (5 / POWER(10, DecimalPlaces + 1)) , DecimalPlaces)