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
2.12 -> 2.15
0.16 -> 0.20
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.
3条答案
按热度按时间b4lqfgs41#
Since 100/5 = 20 all we do is multiply by 20, round up to the nearest whole number, and then divide by 20.
(To round up in MySQL use CEIL)
Example for $1.03:
NOTE: I also round the whole statement to 2 decimals places just to remove any trailing zeros.
EDIT: A generalized example (notice the 100.00 to cast the value as non-integer)
bqjvbblv2#
qnyhuwrf3#
Try to use this one -