Nuancing data

In addition to performing indexing and substituting on data, MySQL also allows for several ways of massaging the data to suit your needs. Some of the more common ones are discussed in this chapter.

ROUND()

As the name suggests, the mathematical function ROUND() serves to round decimal values to a specified number of places. The base value comes first in the syntax:

SELECT ROUND(base value, number of positions);

So rounding an already rough approximation of Pi would look like this:

mysql> SELECT ROUND(22/7, 2) as PI;
+------+
| PI |
+------+
| 3.14 |
+------+
1 row in set (0.00 sec)

The ROUND() function will accept whatever value you give it for the number of positions. However, if the number of places exceeds MySQL's built-in abilities ...

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.