← round operator page · numeric/round/comp_digits/manual_ex_3

Manual example 3 🟢 all ok

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.csv ⇩

Id_1Id_2Me_1Me_2
10A7.55.9
10B7.15.5
11A36.217.7
11B44.524.3

input/DS_1.json ⇩

{
  "datasets": [
    {
      "name": "DS_1",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
        {"name": "Id_2", "type": "String", "role": "Identifier", "nullable": false},
        {"name": "Me_1", "type": "Number", "role": "Measure", "nullable": true},
        {"name": "Me_2", "type": "Number", "role": "Measure", "nullable": true}
      ]
    }
  ]
}

expected/DS_r.csv ⇩

Id_1Id_2Me_1Me_2Me_20
10A7.55.910
10B7.15.510
11A36.217.740
11B44.524.340

expected/DS_r.json ⇩

{
  "datasets": [
    {
      "name": "DS_r",
      "DataStructure": [
        {"name": "Id_1", "type": "Integer", "role": "Identifier"},
        {"name": "Id_2", "type": "String", "role": "Identifier"},
        {"name": "Me_1", "type": "Number", "role": "Measure"},
        {"name": "Me_2", "type": "Number", "role": "Measure"},
        {"name": "Me_20", "type": "Number", "role": "Measure"}
      ]
    }
  ]
}