Skip to content

Commit 701cc7f

Browse files
Merge pull request #33651 from rwestMSFT/rw-0327-fix-408762
Add rounding example to decimal and numeric article (UUF 408762)
2 parents 88420f4 + 8c29c61 commit 701cc7f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/t-sql/data-types/decimal-and-numeric-transact-sql.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Transact-SQL reference for the decimal and numeric data types. Dec
44
author: MikeRayMSFT
55
ms.author: mikeray
66
ms.reviewer: randolphwest
7-
ms.date: 09/24/2024
7+
ms.date: 03/27/2025
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: "reference"
@@ -74,6 +74,8 @@ Before [!INCLUDE [ssSQL16](../../includes/sssql16-md.md)], conversion of **float
7474

7575
## Examples
7676

77+
### A. Create a table using decimal and numeric data types
78+
7779
The following example creates a table using the **decimal** and **numeric** data types. Values are inserted into each column. The results are returned by using a `SELECT` statement.
7880

7981
```sql
@@ -99,6 +101,28 @@ MyDecimalColumn MyNumericColumn
99101
123.00 12345.12000
100102
```
101103

104+
### B. Convert float to decimal with a lower precision and scale
105+
106+
The following example shows how a **float** value is rounded when converted to a **decimal** with a lower precision and scale.
107+
108+
```sql
109+
CREATE TABLE dbo.MyTable (
110+
MyFloatColumn FLOAT,
111+
MyDecimalColumn DECIMAL(10, 3)
112+
);
113+
GO
114+
115+
DECLARE @value FLOAT;
116+
SELECT @value = 12345.123456789;
117+
118+
INSERT INTO dbo.MyTable
119+
VALUES (@value, @value);
120+
GO
121+
122+
SELECT MyFloatColumn, MyDecimalColumn
123+
FROM dbo.MyTable;
124+
```
125+
102126
## Related content
103127

104128
- [ALTER TABLE (Transact-SQL)](../statements/alter-table-transact-sql.md)

0 commit comments

Comments
 (0)