##### Page tree

Release 6.8.2

Contents:

Contents:

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.

## Basic Usage

Numeric literal example:

trunc(pi())

Output: Returns the value 3.

Expression example:

trunc(length_in * length_in, 2)

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

## Syntax and Arguments

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.

### 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.

Usage Notes:

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.

Usage Notes:

Required?Data TypeExample Value
NoInteger literal3

## Examples

### Example - Basic TRUNC

Source:

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

Transformation:

Transformation Name New formula Single row formula trunc(myVal) 'trunc_myVal'

Transformation Name New formula Single row formula trunc(myVal,2) 'trunc_myVal2'

Transformation Name New formula Single row formula trunc(myVal,2) '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

This example illustrates how you can apply the following functions to generate new and random data in your dataset:
• RANDBETWEEN - Generate a random Integer value between two specified Integers. See RANDBETWEEN Function.
• PI - Generate the value of pi to 15 decimal points. See PI Function.
• ROUND - Round a decimal value to the nearest Integer or to a specified number of digits. See ROUND Function.
• TRUNC - Round a value down to the nearest Integer value. See TRUNC Function.

Source:

In the following example, a company produces 10 circular parts, the size of which is measured in each product's radius in inches.

p0011
p0022
p0033
p0044
p0055
p0066
p0077
p0088
p0099
p01010

Based on the above data, the company wants to generate some additional sizing information for these circular parts, including the generation of two points along each part's circumference where quality stress tests can be applied.

Transformation:

To begin, you can use the following steps to generate the area and circumference for each product, rounded to three decimal points:

Transformation Name New formula Single row formula ROUND(PI() * (POW(radius_in, 2)), 3) 'area_sqin'

Transformation Name New formula Single row formula ROUND(PI() * (2 * radius_in), 3) 'circumference_in'

For quality purposes, the company needs two tests points along the circumference, which are generated by calculating two separate random locations along the circumference. Since the RANDBETWEEN function only calculates using Integer values, you must first truncate the values from circumference_in:

Transformation Name New formula Single row formula TRUNC(circumference_in) 'trunc_circumference_in'

Then, you can calculate the random points using the following:

Transformation Name New formula Single row formula RANDBETWEEN(0, trunc_circumference_in) 'testPt01_in'

Transformation Name New formula Single row formula RANDBETWEEN(0, trunc_circumference_in) 'testPt02_in'

Results:

After the trunc_circumference_in column is dropped, the data should look similar to the following:

p00113.1426.28355
p002212.56612.56633
p003328.27418.8501313
p004450.26525.1332424
p005578.54031.41600
p0066113.09737.6991515
p0077153.93843.9821111
p0088201.06250.26511
p0099254.46956.5492929
p01010314.15962.8322121

• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page: