← trunc operator page · numeric/trunc/comp_no_digits/manual_ex_2

Manual example 2 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

trunc with numDigit omitted, on a component inside calc.

Manual:

Truncation, Example 2, output verbatim: "The basic scalar type of the result is integer if numDigit is omitted, number otherwise."

Expected:

Me_10 = trunc(Me_1) is an Integer: 7.5, 7.1, 36.2 and 44.5 give 7, 7, 36 and 44; the other components are kept.

script.vtl ⇩

DS_r := DS_1[ calc Me_10:= trunc( Me_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_10
10A7.55.97
10B7.15.57
11A36.217.736
11B44.524.344

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_10", "type": "Integer", "role": "Measure"}
      ]
    }
  ]
}