Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version r096

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 lang vs sql

D s
snippetBasic

Numeric literal example:

D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value: trunc(pi())

trunc(pi())

Output: Returns the value 3.

Expression example:

D lang syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value: trunc(length_in * length_in, 2)

trunc(length_in * length_in, 2)

Output: Returns the square of the values in length_in, truncated to two decimal points.

D s
snippetSyntax

D lang syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value: trunc(numeric_value,integer_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

Transformation:

D trans
RawWrangletrue
p03Value'trunc_myVal'
Typestep
WrangleTextderive type:single value:trunc(myVal) as: 'trunc_myVal'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuetrunc(myVal)
p03NameNew column name
SearchTermNew formula

D trans
RawWrangletrue
p03Value'trunc_myVal2'
Typestep
WrangleTextderive type:single value:trunc(myVal,2) as: 'trunc_myVal2'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuetrunc(myVal,2)
p03NameNew column name
SearchTermNew formula

D trans
RawWrangletrue
p03Value'trunc_myVal_2'
Typestep
WrangleTextderive type:single value:trunc(myVal,2) as: 'trunc_myVal_2'
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuetrunc(myVal,2)
p03NameNew column name
SearchTermNew formula

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