
There is a challenge in HackerRank. We should find the result of abandoning the decimal point abandoned, not rounded up. How do we deal with decimals in MySQL? we've seen the round. But we've rarely seen abandonment before. Anyway, let's find out how to solve the problem of dealing with decimal points.
MySQL Decimal Abandonment(Down) Method
The way to abandon the decimal point is to use FLOOR right away. So, the answer to this question is as followed.
SELECT FLOOR(AVG(POPULATION))
FROM CITY
How to raise and round MySQL decimal points
I'm going to write those cases in this pharagraph because it's too empty to write raise and round functions separately. For raise, we can use the CEIL() function. It is came from ceiling. For Rounding, we can use the ROUND() function. You can tell by intuition that it came from rounding.
How to raise and round MySQL decimal points
Question that arise at this time:
Hey, for rounding up or down, we don't need to specify the decimal place, but for standard rounding, don't we have to specify which digit to round to?
That's right. And that's why we need to write down specified digit when we use the standard round function. If you faced the problem like this, you might think reflexively that you should write down the number of digits in the round function before you even think about it. (I think it's just kind of instincts to write it down.) In conclusion, we have to write ROUND(number, spcified digits to round to). For example, if you want to indicate the second decimal place in 3.141592, then you should do ROUND(3.141592, 2). Then, you'll get 3.14. you don't have to memorize. Just trust your instincts.
'IT, Digital' 카테고리의 다른 글
| Blog AdSense Revenue Journey: How to fix the ads.txt issue in Adsense? (0) | 2025.06.02 |
|---|---|
| An application to use desktops remotely from your iPad, Jump Desktop (0) | 2025.06.01 |
| [MySQL] SQL SELF JOIN & DATE type format (0) | 2025.05.31 |
| [MySQL] What is SELF JOIN? (0) | 2025.05.30 |
| [MySQL] How to include NULL value in AVG function (0) | 2025.05.28 |
