Home >Database >Mysql Tutorial >How to Format a Number with Two Decimal Places in SQL Server?
Achieving Two Decimal Place Precision in SQL Server
Data formatting is crucial for consistent data presentation. This guide demonstrates how to easily format numbers to two decimal places within SQL Server.
The most effective method utilizes the CONVERT
function with the DECIMAL
data type:
<code class="language-sql">SELECT CONVERT(DECIMAL(10,2), YourColumnName)</code>
Remember to substitute "YourColumnName"
with your actual column name. DECIMAL(10,2)
defines the data type; 10
represents the total number of digits (precision), and 2
signifies the number of decimal places (scale).
Example:
The following query:
<code class="language-sql">SELECT CONVERT(DECIMAL(10,2), 2.999999)</code>
Will produce the output: 3.00
This technique ensures your numerical data is displayed with the required level of decimal precision.
The above is the detailed content of How to Format a Number with Two Decimal Places in SQL Server?. For more information, please follow other related articles on the PHP Chinese website!