MySQL 向上取整至最接近的 5 美分 [英] MySQL Round Up to Nearest 5 Cents

查看:85
本文介绍了MySQL 向上取整至最接近的 5 美分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 MySQL 将值四舍五入到 5 美分 (0.05) 的增量.它必须总是四舍五入.例子:

I need to round up values using MySQL to increments of 5 cents (0.05). It has to ALWAYS round up. Examples:

0.01 -> 0.05

0.01 -> 0.05

2.12 -> 2.15

2.12 -> 2.15

0.16 -> 0.20

0.16 -> 0.20

我怎样才能做到这一点.我用 ceil() 和 round() 尝试了一些东西,但似乎我可以使用 MySQL 专家的一些帮助.

How can I accomplish this. I tried a few things with ceil() and round(), but it seems like I can use some help from a MySQL expert.

推荐答案

尝试使用这个 -

SELECT (<value> DIV 0.05) * 0.05 + IF(<value> MOD 0.05 = 0, 0, 0.05)

这篇关于MySQL 向上取整至最接近的 5 美分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆