Rounding · round
---
config:
flowchart:
useMaxWidth: false
---
flowchart TB
classDef ok fill:#d4edda,stroke:#28a745,color:#000
classDef partial fill:#fff3cd,stroke:#ffc107,color:#000
classDef refused fill:#d4edda,stroke:#28a745,stroke-width:3px,stroke-dasharray: 2 2,color:#000
classDef missing fill:#f8d7da,stroke:#dc3545,color:#000
classDef diverge fill:#cce5ff,stroke:#007bff,color:#000
classDef block fill:#2b3a4a,stroke:#2b3a4a,color:#fff,font-weight:bold
classDef ext fill:#fff,stroke:#666,color:#000,stroke-dasharray: 5 5
O["Rounding · round<br/>🟢11"]:::ok
subgraph G_ds["Dataset"]
direction LR
v_ds_digits["round(DS, n)"]:::ok
v_ds_no_digits["round(DS)"]:::ok
v_ds_placeholder["round(DS, _)"]:::ok
end
subgraph G_comp["Component"]
direction LR
v_comp_digits["round(comp, n)"]:::ok
v_comp_no_digits["round(comp)"]:::ok
v_comp_placeholder["round(comp, _)"]:::ok
v_comp_comp_digits["round(comp, comp)"]:::ok
v_sc_comp_digits["round(sc, comp)"]:::ok
end
subgraph G_sc["Scalar"]
direction LR
v_sc_digits["round(sc, n)"]:::ok
v_sc_no_digits["round(sc)"]:::ok
v_sc_placeholder["round(sc, _)"]:::ok
end
O --- G_ds
O --- G_comp
O --- G_sc
style G_ds fill:#f8f9fa,stroke:#495057,stroke-width:2px
style G_comp fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 8 5
style G_sc fill:#f8f9fa,stroke:#495057,stroke-width:2px,stroke-dasharray: 2 3
click v_ds_digits href "#form-ds-digits"
click v_ds_no_digits href "#form-ds-no-digits"
click v_ds_placeholder href "#form-ds-placeholder"
click v_comp_digits href "#form-comp-digits"
click v_comp_no_digits href "#form-comp-no-digits"
click v_comp_placeholder href "#form-comp-placeholder"
click v_comp_comp_digits href "#form-comp-comp-digits"
click v_sc_comp_digits href "#form-sc-comp-digits"
click v_sc_digits href "#form-sc-digits"
click v_sc_no_digits href "#form-sc-no-digits"
click v_sc_placeholder href "#form-sc-placeholder"
Types
Takes number, integer · Gives number, integer
Comes from · number, integer — 44 operators in 6 blocks 🟢44
General purpose operators (2) 🟢2
String operators (3) 🟢3
Numeric operators (17) 🟢17
Time operators (9) 🟢9
Aggregate and Analytic operators (10) 🟢10
Data validation operators (3) 🟢3
Comes from · operators that return any type (their input's) — 37 operators in 8 blocks 🟢37
General purpose operators (5) 🟢5
Join operators (4) 🟢4
Time operators (3) 🟢3
Set operators (4) 🟢4
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (8) 🟢8
Conditional operators (3) 🟢3
Goes to · number, integer — 43 operators in 8 blocks 🟢43
General purpose operators (1) 🟢1
String operators (2) 🟢2
Numeric operators (17) 🟢17
Time operators (6) 🟢6
Hierarchical aggregation (1) 🟢1
Aggregate and Analytic operators (10) 🟢10
Data validation operators (2) 🟢2
Definitions (VTL-DL) (4) 🟢4
Goes to · operators that take any scalar — 46 operators in 8 blocks 🟢46
General purpose operators (6) 🟢6
Join operators (4) 🟢4
Comparison operators (11) 🟢11
Set operators (4) 🟢4
Aggregate and Analytic operators (8) 🟢8
Data validation operators (1) 🟢1
Conditional operators (3) 🟢3
Forms
round(DS, n) 🟢 · number, integer → number
Manual example 1 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundto 0 digits on every measure ofDS_1.- Manual:
Rounding, Example 1, output verbatim: “The operator round rounds the operand to a number of positions at the right of the decimal point equal to the numDigit parameter.”
- Expected:
Me_17.5, 7.1, 36.2 and 44.5 give 8.0, 7.0, 36.0 and 45.0;Me_25.9, 5.5, 17.7 and 24.3 give 6.0, 6.0, 18.0 and 24.0. Both stay Number, asnumDigitis given.
DS_r := round(DS_1, 0);
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 8.0 | 6.0 |
| 10 | B | 7.0 | 6.0 |
| 11 | A | 36.0 | 18.0 |
| 11 | B | 45.0 | 24.0 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(DS) 🟢 · number → integer
One number measure 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundwithnumDigitomitted, on a dataset with one Number measure.- Manual:
Rounding: “The basic scalar type of the result is integer if numDigit is omitted”, and in the Typical behaviours, “Operators changing the data type”, the measure whose type changes is replaced: “A default generic Measure is assigned by default to the result Data Set, depending on the data type of the result”,
int_varfor an Integer.- Expected:
int_var, an Integer: 3.14159, 2.71828 and 12345.6 give 3, 3 and 12346.
DS_r := round(DS_1);
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | int_var |
|---|---|
| 1 | 3 |
| 2 | 3 |
| 3 | 12346 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
Two number measures 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundwithnumDigitomitted, on a dataset with two Number measures.- Manual:
Rounding: “The basic scalar type of the result is integer if numDigit is omitted”; the result is typed
dataset { measure<number> _+ }, and the unary operators give “homonymous Measures in DS_r”.- Expected:
both measures keep their names and become Integers:
Me_13, 3 and 7,Me_212346, 0 and 6. Ceiling and Floor Example 1 do the same, and nothing putsroundamong the “Operators changing the data type”, which allow one measure only.
DS_r := round(DS_1);
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.14159 | 12345.6 |
| 2 | 2.71828 | 0.4 |
| 3 | 7.2 | 5.9 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3 | 12346 |
| 2 | 3 | 0 |
| 3 | 7 | 6 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(DS, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a dataset with one Number measure.- Manual:
Rounding: “
round ( 12345.6, _ )gives12346”, and in the Typical behaviours, “Operators changing the data type”, the measure whose type changes is replaced: “A default generic Measure is assigned by default to the result Data Set, depending on the data type of the result”,int_varfor an Integer.- Expected:
the placeholder stands for an omitted
numDigit, so the result is an Integer, as withround(DS_1):int_var3, 3 and 12346.
DS_r := round(DS_1, _);
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | int_var |
|---|---|
| 1 | 3 |
| 2 | 3 |
| 3 | 12346 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(comp, n) 🟢 · number, integer → number
Manual example 3 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundto a negative number of digits, on a component insidecalc.- Manual:
Rounding, Example 3, output verbatim: “If numDigit is negative, the rounding happens at the left of the decimal point.”
- Expected:
Me_20 = round(Me_1, -1)rounds to tens: 7.5, 7.1, 36.2 and 44.5 give 10, 10, 40 and 40; the other components are kept.
DS_r := DS_1 [ calc Me_20:= round( Me_1 , -1 ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_20 |
|---|---|---|---|---|
| 10 | A | 7.5 | 5.9 | 10 |
| 10 | B | 7.1 | 5.5 | 10 |
| 11 | A | 36.2 | 17.7 | 40 |
| 11 | B | 44.5 | 24.3 | 40 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(comp) 🟢 · number → integer
Manual example 2 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundwithnumDigitomitted, on a component insidecalc.- Manual:
Rounding, Example 2, output verbatim: “The basic scalar type of the result is integer if numDigit is omitted, number otherwise.”
- Expected:
Me_10 = round(Me_1)is an Integer: 7.5, 7.1, 36.2 and 44.5 give 8, 7, 36 and 45; the other components are kept.
DS_r := DS_1 [ calc Me_10:= round( Me_1 ) ];
| Id_1 | Id_2 | Me_1 | Me_2 |
|---|---|---|---|
| 10 | A | 7.5 | 5.9 |
| 10 | B | 7.1 | 5.5 |
| 11 | A | 36.2 | 17.7 |
| 11 | B | 44.5 | 24.3 |
| Id_1 | Id_2 | Me_1 | Me_2 | Me_10 |
|---|---|---|---|---|
| 10 | A | 7.5 | 5.9 | 8 |
| 10 | B | 7.1 | 5.5 | 7 |
| 11 | A | 36.2 | 17.7 | 36 |
| 11 | B | 44.5 | 24.3 | 45 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(comp, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a component insidecalc.- Manual:
Rounding: “
round ( 12345.6, _ )gives12346”.- Expected:
Me_2 = round(Me_1, _)is an Integer, as withnumDigitomitted: 3.14159, 2.71828 and 12345.6 give 3, 3 and 12346; the other components are kept.
DS_r := DS_1[calc Me_2 := round(Me_1, _)];
| Id_1 | Me_1 |
|---|---|
| 1 | 3.14159 |
| 2 | 2.71828 |
| 3 | 12345.6 |
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.141590 | 3 |
| 2 | 2.718280 | 3 |
| 3 | 12345.600000 | 12346 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(comp, comp) 🟢 · number, integer → number
Digits from component 🟢 pandas ✅ · DuckDB ✅
- Tests:
numDigitgiven by an Integer component, which may be negative.- Manual:
Rounding types
numDigitascomponent<integer> | integer, and “round ( 12345.6, -1 )gives12350.0”.- Expected:
Me_3 = round(Me_1, Me_2):round(3.14159, 2) = 3.14,round(2.71828, 3) = 2.718andround(12345.6, -1) = 12350.0, a Number; the other components are kept.
DS_r := DS_1[calc Me_3 := round(Me_1, Me_2)];
| Id_1 | Me_1 | Me_2 |
|---|---|---|
| 1 | 3.14159 | 2 |
| 2 | 2.71828 | 3 |
| 3 | 12345.6 | -1 |
| Id_1 | Me_1 | Me_2 | Me_3 |
|---|---|---|---|
| 1 | 3.141590 | 2 | 3.140000 |
| 2 | 2.718280 | 3 | 2.718000 |
| 3 | 12345.600000 | -1 | 12350.000000 |
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/DS_r.csv · expected/DS_r.json · example page ↗
round(sc, comp) 🟢 · number, integer → number
Digits from component 🟢 pandas ✅ · DuckDB ✅
- Tests:
a scalar operand with
numDigitgiven by an Integer component, insidecalc.- Manual:
Rounding types
numDigitascomponent<integer> | integer, so it may be a component while the operand is a scalar.- Expected:
the error
1-1-15-8, “At op {op}: {op} operator cannot have a {comp_type} as parameter”: by a team decision,numDigitis a Component only when the operand is a Component too.
DS_r := DS_1[calc Me_2 := round(3.14159, Me_1)];
| Id_1 | Me_1 |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | 0 |
Expected error 1-1-15-8: At op {op}: {op} operator cannot have a {comp_type} as parameter.
Files: script.vtl · input/DS_1.csv · input/DS_1.json · expected/error.json · example page ↗
round(sc, n) 🟢 · number, integer → number
Rounds up at fourth decimal 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundof a scalar withnumDigitgiven:round(SC_1, SC_2)withSC_1= 3.14159 andSC_2= 4.- Manual:
Rounding: “
round ( 3.14159, 4 )gives3.1416”.- Expected:
SC_r = 3.1416, a Number: the fifth decimal 9 adds 1 to the fourth.
SC_r := round(SC_1, SC_2);
| SC_1 | SC_2 |
|---|---|
| 3.14159 | 4 |
Name |
Type |
Value |
|---|---|---|
|
Number |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
round(sc) 🟢 · number → integer
Rounds up to integer 🟢 pandas ✅ · DuckDB ✅
- Tests:
roundof a scalar withnumDigitomitted:round(SC_1)withSC_1= 12345.6.- Manual:
Rounding: “
round ( 12345.6 )gives12346”, and “The basic scalar type of the result is integer if numDigit is omitted”.- Expected:
SC_r = 12346, an Integer.
SC_r := round(SC_1);
| SC_1 |
|---|
| 12345.6 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗
round(sc, _) 🟢 · number → integer
Placeholder for digits 🟢 pandas ✅ · DuckDB ✅
- Tests:
the placeholder
_fornumDigit, on a scalar:round(SC_1, _)withSC_1= 12345.6.- Manual:
Rounding: “
round ( 12345.6, _ )gives12346”.- Expected:
SC_r = 12346, an Integer: the placeholder stands for an omittednumDigit.
SC_r := round(SC_1, _);
| SC_1 |
|---|
| 12345.6 |
Name |
Type |
Value |
|---|---|---|
|
Integer |
|
Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗