Home >Database >Mysql Tutorial >How to Round Minutes to Hours with Two Decimal Places in SQL?
Rounding Hours to Two Decimal Places with SQL
To convert minutes to hours and round the result to two decimal places, one approach is to use the ROUND function. However, the issue arises when the result contains more than two digits after the decimal point.
In the given example, dividing 630 minutes by 60 results in 10.5000000. To display only 10.50 after rounding, the result can be cast as a NUMERIC data type with a specified precision and scale.
Specifically, you would use CAST(ROUND(Minutes/60.0,2) AS NUMERIC(x,2)) where x is an integer less than or equal to 38. The following query demonstrates this approach:
SELECT ROUND(630/60.0,2), -- Output: 10.500000 CAST(ROUND(630/60.0,2) AS NUMERIC(36,2)) -- Output: 10.50
The above is the detailed content of How to Round Minutes to Hours with Two Decimal Places in SQL?. For more information, please follow other related articles on the PHP Chinese website!