I have a table called "itemprices" and there is a field called "price". I need to query the price value with it's GST value which is 10% of the price value, and more importantly that value must be rounded to two decimals.
If the price = 70.85, GST value = 7.085 (price / 100 * 10);
- A) When I use ROUND function with the above calculation, it will return 7.08
- B) When I use ROUND function with 7.085 directly, it will return 7.09
(Actually I would like to have 7.09 in both situations)
See below query.
SELECT
price,
(price / 100 * 10) AS gstvalue,
ROUND( (price / 100 * 10), 2 ) AS roundedgstvalue,
ROUND( 7.085, 2 ) AS customround FROM `itemprices`
WHERE id = 10
Returned values are as below.
- price = 70.85
- gstvalue = 7.085
- roundedgstvalue = 7.08
- customround = 7.09
I'm using MySQL version 5.1.41 and I would like to know why the ROUND function is behaving differently in the situations A and B.
Also I would like to have a solution to get the value 7.09 for the situation B.
Appreciate your comments and answers. Thank you!