Home > Database > Mysql Tutorial > body text

How can we retrieve the output of the decimal value of a column in a specified format?

PHPz
Release: 2023-09-09 09:53:17
forward
1299 people have browsed it

How can we retrieve the output of the decimal value of a column in a specified format?

MySQL FORMAT() function converts numbers into formats such as #,

,

.

, rounds to the specified number of decimal places, and Returns the result as a string, which can be used to retrieve output with the decimal value of a column in the specified format. To understand it, let us take the table "estimated_cost" as an example, which contains the following data -

mysql> Select * from estimated_cost;
+----+-----------------+-----------+---------------+
| Id | Name_Company    | Tender_id | Tender_value  |
+----+-----------------+-----------+---------------+
| 1  | ABC Ltd.        | 110       | 256.3256879   |
| 2  | Chd Ltd.        | 116       | 8569.25647879 |
| 3  | City group Ltd. | 202       | 23647.2365987 |
| 4  | Hjkl Ltd.       | 215       | 6598.327846   |
+----+-----------------+-----------+---------------+
4 rows in set (0.00 sec)
Copy after login

Now, suppose we want to see the value of the "Tender_value" column (up to a specified number of decimal places), then we can take the help of the following Query to complete -

mysql> Select FORMAT(Tender_value,2) from estimated_cost;
+------------------------+
| FORMAT(Tender_value,2) |
+------------------------+
| 256.33                 |
| 8,569.26               |
| 23,647.24              |
| 6,598.33               |
+------------------------+
4 rows in set (0.00 sec)

Copy after login

The above query returns the value of Tender_value, up to 2 decimal places. ###
mysql> Select FORMAT(Tender_value,1) from estimated_cost1;
+------------------------+
| FORMAT(Tender_value,1) |
+------------------------+
| 256.3                  |
| 8,569.3                |
| 23,647.2               |
| 6,598.3                |
+------------------------+
4 rows in set (0.00 sec)
Copy after login
###The above query returns the value of Tender_value, retaining up to 1 decimal place. ###

The above is the detailed content of How can we retrieve the output of the decimal value of a column in a specified format?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template