Rounding · round

🟢 11 of 11 forms all ok · VTL 2.2 Reference Manual ↗ · vtlengine 1.10.0rc3 (9e1c81a6) · pandas 2.3.3 · DuckDB 1.5.5
🟢 all ok🟡 partially implemented🛡️ refused with an error🔴 not implemented or crash🔵 engines differ ✅ match · ❌ wrong result · 🛡 guarded error (code) · 💥 crash · 📌 team decision
Dataset formsComponent formsScalar forms
        ---
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
Clause operators (9) 🟢9
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
Clause operators (9) 🟢9

Forms

round(DS, n) 🟢 · number, integer → number

Manual example 1 🟢 pandas ✅ · DuckDB ✅
Tests:

round to 0 digits on every measure of DS_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_1 7.5, 7.1, 36.2 and 44.5 give 8.0, 7.0, 36.0 and 45.0; Me_2 5.9, 5.5, 17.7 and 24.3 give 6.0, 6.0, 18.0 and 24.0. Both stay Number, as numDigit is given.

script.vtl
DS_r := round(DS_1, 0);
Input DS_1
Id_1Id_2Me_1Me_2
10A7.55.9
10B7.15.5
11A36.217.7
11B44.524.3
Expected DS_r
Id_1Id_2Me_1Me_2
10A8.06.0
10B7.06.0
11A36.018.0
11B45.024.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:

round with numDigit omitted, 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_var for an Integer.

Expected:

int_var, an Integer: 3.14159, 2.71828 and 12345.6 give 3, 3 and 12346.

script.vtl
DS_r := round(DS_1);
Input DS_1
Id_1Me_1
13.14159
22.71828
312345.6
Expected DS_r
Id_1int_var
13
23
312346

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:

round with numDigit omitted, 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_1 3, 3 and 7, Me_2 12346, 0 and 6. Ceiling and Floor Example 1 do the same, and nothing puts round among the “Operators changing the data type”, which allow one measure only.

script.vtl
DS_r := round(DS_1);
Input DS_1
Id_1Me_1Me_2
13.1415912345.6
22.718280.4
37.25.9
Expected DS_r
Id_1Me_1Me_2
1312346
230
376

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 _ for numDigit, on a dataset with one Number measure.

Manual:

Rounding: “round ( 12345.6, _ ) gives 12346”, 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_var for an Integer.

Expected:

the placeholder stands for an omitted numDigit, so the result is an Integer, as with round(DS_1): int_var 3, 3 and 12346.

script.vtl
DS_r := round(DS_1, _);
Input DS_1
Id_1Me_1
13.14159
22.71828
312345.6
Expected DS_r
Id_1int_var
13
23
312346

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:

round to a negative number of digits, on a component inside calc.

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.

script.vtl
DS_r := DS_1 [ calc Me_20:= round( Me_1 , -1 ) ];
Input DS_1
Id_1Id_2Me_1Me_2
10A7.55.9
10B7.15.5
11A36.217.7
11B44.524.3
Expected DS_r
Id_1Id_2Me_1Me_2Me_20
10A7.55.910
10B7.15.510
11A36.217.740
11B44.524.340

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:

round with numDigit omitted, on a component inside calc.

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.

script.vtl
DS_r := DS_1 [ calc Me_10:= round( Me_1 ) ];
Input DS_1
Id_1Id_2Me_1Me_2
10A7.55.9
10B7.15.5
11A36.217.7
11B44.524.3
Expected DS_r
Id_1Id_2Me_1Me_2Me_10
10A7.55.98
10B7.15.57
11A36.217.736
11B44.524.345

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 _ for numDigit, on a component inside calc.

Manual:

Rounding: “round ( 12345.6, _ ) gives 12346”.

Expected:

Me_2 = round(Me_1, _) is an Integer, as with numDigit omitted: 3.14159, 2.71828 and 12345.6 give 3, 3 and 12346; the other components are kept.

script.vtl
DS_r := DS_1[calc Me_2 := round(Me_1, _)];
Input DS_1
Id_1Me_1
13.14159
22.71828
312345.6
Expected DS_r
Id_1Me_1Me_2
13.1415903
22.7182803
312345.60000012346

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:

numDigit given by an Integer component, which may be negative.

Manual:

Rounding types numDigit as component<integer> | integer, and “round ( 12345.6, -1 ) gives 12350.0”.

Expected:

Me_3 = round(Me_1, Me_2): round(3.14159, 2) = 3.14, round(2.71828, 3) = 2.718 and round(12345.6, -1) = 12350.0, a Number; the other components are kept.

script.vtl
DS_r := DS_1[calc Me_3 := round(Me_1, Me_2)];
Input DS_1
Id_1Me_1Me_2
13.141592
22.718283
312345.6-1
Expected DS_r
Id_1Me_1Me_2Me_3
13.14159023.140000
22.71828032.718000
312345.600000-112350.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 numDigit given by an Integer component, inside calc.

Manual:

Rounding types numDigit as component<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, numDigit is a Component only when the operand is a Component too.

script.vtl
DS_r := DS_1[calc Me_2 := round(3.14159, Me_1)];
Input DS_1
Id_1Me_1
12
24
30

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:

round of a scalar with numDigit given: round(SC_1, SC_2) with SC_1 = 3.14159 and SC_2 = 4.

Manual:

Rounding: “round ( 3.14159, 4 ) gives 3.1416”.

Expected:

SC_r = 3.1416, a Number: the fifth decimal 9 adds 1 to the fourth.

script.vtl
SC_r := round(SC_1, SC_2);
Input scalars
SC_1SC_2
3.141594
Expected scalars

Name

Type

Value

SC_r

Number

"3.141600"

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:

round of a scalar with numDigit omitted: round(SC_1) with SC_1 = 12345.6.

Manual:

Rounding: “round ( 12345.6 ) gives 12346”, and “The basic scalar type of the result is integer if numDigit is omitted”.

Expected:

SC_r = 12346, an Integer.

script.vtl
SC_r := round(SC_1);
Input scalars
SC_1
12345.6
Expected scalars

Name

Type

Value

SC_r

Integer

"12346"

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 _ for numDigit, on a scalar: round(SC_1, _) with SC_1 = 12345.6.

Manual:

Rounding: “round ( 12345.6, _ ) gives 12346”.

Expected:

SC_r = 12346, an Integer: the placeholder stands for an omitted numDigit.

script.vtl
SC_r := round(SC_1, _);
Input scalars
SC_1
12345.6
Expected scalars

Name

Type

Value

SC_r

Integer

"12346"

Files: script.vtl · input/scalars.csv · input/scalars.json · expected/scalars.json · example page ↗