Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

D toc
Excerpt

Removes all digits to the right of the decimal point for any value. Optionally, you can specify the number of digits to which to round. Input can be an Integer, a Decimal, a column reference, or an expression. 


D s
snippetBasic

Numeric literal example:

D code

derive type:single value: TRUNC(PI())

Output: Generates a column with each row's value 3.

Expression example:

D code

derive type:single value: TRUNC(length_in * length_in, 2)

Output: Generates a column containing the square of the values in length_in, truncated to two decimal points.

D s
snippetSyntax

D code

derive type:single value: TRUNC(numeric_value,integer_value)

ArgumentRequired?Data TypeDescription
numeric_valueYstring, decimal, or integerName of column or Decimal or Integer literal to apply to the function
integer_valueNinteger

Number of digits to which to truncate.

  • Default is 0, which truncates to the nearest integer.
  • Negative integer values can be applied.

D s lang notes

numeric_value

Name of the column, numeric literal, or numeric expression.

  • Missing input values generate missing results.
  • Literal numeric values should not be quoted. Quoted values are treated as strings. 
  • Multiple columns and wildcards are not supported.

D s
snippetusage

Required?Data TypeExample Value
YesString (column reference) or Integer or Decimal literal2.5

integer_value

Number of digits to which to round the first argument of the function.

  • Positive values values truncate to the right of the decimal point.
  • Negative values truncate to the left of the decimal point.
  • Missing input values generate missing results.

D s
snippetusage

Required?Data TypeExample Value
NoInteger literal3

D s
snippetExamples

Example - Basic TRUNC

Source:

RowIdmyVal
r011.2345
r02-1.2345
r03100.000
r0410.1
r0550.029

Transform:

D code

derive type:single value:TRUNC(myVal) as: 'trunc_myVal'

D code

derive type:single value:TRUNC(myVal,2) as: 'trunc_myVal2'

D code

derive type:single value:TRUNC(myVal,2) as: 'trunc_myVal_2'

Results:

RowIdmyValtrunc_myValtrunc_myVal2trunc_myVal_2
r011.234511.230
r02-1.2345-1-1.230
r03100.000100100.00100
r0410.11010.10
r0550.0295050.020

Example - RANDBETWEEN, PI, and TRUNC functions

Include Page
EXAMPLE - RANDBETWEEN and PI Functions
EXAMPLE - RANDBETWEEN and PI Functions

D s also
labelmath