← trunc operator page · numeric/trunc/ds_digits/manual_ex_1

Manual example 1 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

trunc to 0 digits on every measure of DS_1.

Manual:

Truncation, Example 1, output verbatim: "The operator trunc truncates 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 7.0, 7.0, 36.0 and 44.0; Me_2 5.9, 5.5, 17.7 and 24.3 give 5.0, 5.0, 17.0 and 24.0. Both stay Number, as numDigit is given.

script.vtl ⇩

DS_r := trunc(DS_1, 0);

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_2
10A7.05.0
10B7.05.0
11A36.017.0
11B44.024.0

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"}
      ]
    }
  ]
}