Select*fromestimated_cost;+----+-----------------+-- ----------+---------------+|Id|Name_Company |Te"/> Select*fromestimated_cost;+----+-----------------+-- ----------+---------------+|Id|Name_Company |Te">

Home  >  Article  >  Database  >  How can we retrieve the output of the decimal value of a column in a specified format?

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

PHPz
PHPzforward
2023-09-09 09:53:171296browse

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)

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)

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)
###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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete