Data types and expressions
Numeric functions
Round calculated prices with an explicit precision.
Lesson 24 of 84
Reading: about 2 min
Lesson + practice: about 12 min
Difficulty: Beginner
On this page4 sections
This lesson uses the unmodified DDI_SQL_Training dataset v1.0.0 on SQL Server 2019 or later. Round calculated prices with an explicit precision.
Run the example
sql
SELECT TOP (3) ProductID, ListPrice,
ROUND(ListPrice * 1.10, 2) AS PriceWithTenPercent
FROM dbo.Products
ORDER BY ProductID;Read it step by step
- ListPrice is decimal(10,2), so the multiplication uses exact decimal arithmetic.
- ROUND(..., 2) rounds the computed result to two decimal places; its displayed scale can still be wider.
- ORDER BY ProductID identifies the first three products consistently.
Check the result
| ProductID | ListPrice | PriceWithTenPercent |
|---|---|---|
| 1 | 39.00 | 42.9000 |
| 2 | 129.00 | 141.9000 |
| 3 | 79.00 | 86.9000 |
These are calculated prices, not updates to ListPrice.
Practice
For Products 1 and 2, show the absolute difference between ListPrice and 50.
Check your answer and expected result
Reveal answer
sql
SELECT ProductID, ABS(ListPrice - 50) AS DistanceFrom50
FROM dbo.Products
WHERE ProductID IN (1, 2)
ORDER BY ProductID;| ProductID | DistanceFrom50 |
|---|---|
| 1 | 11.00 |
| 2 | 79.00 |
ABS removes the sign from each difference; neither source price changes.
Your progress
Reveal the check answer or reach the end to complete this lesson.