← trunc operator page · numeric/trunc/comp_comp_digits/digits_from_component

Digits from component 🟢 all ok

pandas ✅ · DuckDB ✅

Tests:

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

Manual:

Truncation types numDigit as component<integer> | integer, and "trunc( 12345.6, -1 ) gives 12340.0".

Expected:

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

script.vtl ⇩

DS_r := DS_1[calc Me_3 := trunc(Me_1, Me_2)];

input/DS_1.csv ⇩

Id_1Me_1Me_2
13.141592
22.718283
312345.6-1

input/DS_1.json ⇩

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

expected/DS_r.csv ⇩

Id_1Me_1Me_2Me_3
13.14159023.140000
22.71828032.718000
312345.600000-112340.000000

expected/DS_r.json ⇩

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