From 963ac67e9bbddcfdd4bba0390104989413e9a9c9 Mon Sep 17 00:00:00 2001 From: Stuart Mosquera Date: Mon, 1 Sep 2025 18:31:44 -0300 Subject: [PATCH 1/2] create round.md --- .../math-functions/terms/round/round.md | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 content/sql/concepts/math-functions/terms/round/round.md diff --git a/content/sql/concepts/math-functions/terms/round/round.md b/content/sql/concepts/math-functions/terms/round/round.md new file mode 100644 index 00000000000..e89d4aa6a65 --- /dev/null +++ b/content/sql/concepts/math-functions/terms/round/round.md @@ -0,0 +1,67 @@ +--- +Title: 'ROUND()' +Description: 'Returns the number rounded to the specified number of decimal places.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'SQL' + - 'MySQL' + - 'PostgreSQL' + - 'SQLite' + - 'Functions' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +The SQL math function **`ROUND()`** returns the number rounded to the specified number of decimal places. If no decimal places are provided, the number is rounded without decimals. + +> **Note:** In some RDBMS like SQL Server, there may be an optional third parameter to truncate instead of round. + +## Syntax + +```sql +ROUND(number, decimals) +``` + +**Parameters:** + +- `number`: The number to be rounded. +- `decimals` (optional): The number of decimal places to round to. + +**Return value:** + +Returns the number rounded to the specified number of decimal places. + +## Example 1 + +In this example, the `ROUND()` function is used with a single argument. + +```sql +SELECT ROUND(25.50); -- Result: 26 +``` + +## Example 2 + +In this example, the following data is given in the `sales` table: + +| id | total | +| --- | ------- | +| 1 | 123.456 | +| 2 | 987.654 | + +The `ROUND()` function is used with the second optional argument `decimals`, setting the number of decimal places to 1: + +```sql +SELECT id, ROUND(total, 1) AS total_rounded FROM sales; +``` + +In this SQL statement, the total values are rounded to get the total_rounded. The [AS](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column total_rounded in the output. + +The output will be: + +| id | total_rounded | +| --- | ------------- | +| 1 | 123.5 | +| 2 | 987.7 | From 004cbabafea4e1f5db411dc6916c7b59a578de90 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Tue, 16 Sep 2025 10:37:18 +0530 Subject: [PATCH 2/2] added output block for example 1 --- .../math-functions/terms/round/round.md | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/content/sql/concepts/math-functions/terms/round/round.md b/content/sql/concepts/math-functions/terms/round/round.md index e89d4aa6a65..77f909cb66c 100644 --- a/content/sql/concepts/math-functions/terms/round/round.md +++ b/content/sql/concepts/math-functions/terms/round/round.md @@ -5,11 +5,11 @@ Subjects: - 'Computer Science' - 'Data Science' Tags: - - 'SQL' + - 'Functions' - 'MySQL' - 'PostgreSQL' + - 'SQL' - 'SQLite' - - 'Functions' CatalogContent: - 'learn-sql' - 'paths/analyze-data-with-sql' @@ -21,7 +21,7 @@ The SQL math function **`ROUND()`** returns the number rounded to the specified ## Syntax -```sql +```pseudo ROUND(number, decimals) ``` @@ -36,12 +36,20 @@ Returns the number rounded to the specified number of decimal places. ## Example 1 -In this example, the `ROUND()` function is used with a single argument. +In this example, the `ROUND()` function is used with a single argument: ```sql -SELECT ROUND(25.50); -- Result: 26 +SELECT ROUND(25.50); ``` +The output this code generates is: + +| ROUND(25.50) | +| ------------ | +| 26 | + +> **Note:** When no decimal places are provided, `ROUND()` returns the nearest integer. + ## Example 2 In this example, the following data is given in the `sales` table: @@ -57,7 +65,7 @@ The `ROUND()` function is used with the second optional argument `decimals`, set SELECT id, ROUND(total, 1) AS total_rounded FROM sales; ``` -In this SQL statement, the total values are rounded to get the total_rounded. The [AS](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column total_rounded in the output. +In this SQL statement, the total values are rounded to get the `total_rounded`. The [`AS`](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column `total_rounded` in the output. The output will be: