How to make numbers 'human readable' in MySQL?


To make numbers ‘human readable’ i.e. including separators, you need to use format(). Let us first create a table −

mysql> create table DemoTable859(Number bigint);
Query OK, 0 rows affected (1.54 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable859 values(747464646473737);
Query OK, 1 row affected (0.45 sec)
mysql> insert into DemoTable859 values(3836365366464);
Query OK, 1 row affected (0.71 sec)
mysql> insert into DemoTable859 values(8376437647433);
Query OK, 1 row affected (0.46 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable859;

This will produce the following output −

+-----------------+
| Number          |
+-----------------+
| 747464646473737 |
| 3836365366464   |
| 8376437647433   |
+-----------------+
3 rows in set (0.00 sec)

Following is the query to make numbers 'human readable' in MySQL −

mysql> select format(Number, 0) AS HumanReadableFormat from DemoTable859;

This will produce the following output −

+---------------------+
| HumanReadableFormat |
+---------------------+
| 747,464,646,473,737 |
| 3,836,365,366,464   |
| 8,376,437,647,433   |
+---------------------+
3 rows in set (0.00 sec)

Updated on: 03-Sep-2019

263 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements