Truncate Number
Verb: truncateNumber
Truncates a number by returning the integer part, decimal part, or by rounding it.
Syntax
truncateNumber --value(Numeric) --type(TruncateType) [--decimalasinteger(Boolean)] --precision(Numeric) (Numeric)=value
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--value | Number | Required | Number | Number to be truncated. |
--type | Truncation Type | Required | TruncateType | Type of truncation to be done. Options:
|
--decimalasinteger | Decimal as integer | Optional | Boolean | Returns only the numbers after the decimal point, as an integer.
As an example, the number 5.3 will return 3. |
--precision | Precision | Only whenTruncation Type is Round | Number | Defines the number of decimal places to consider when rounding. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Value | Number | Returns the truncated number. |
Example
Example 1: A numeric variable called - "truncated number" - is defined, which receives the result of the truncation of the number 8.9 with the parameter Integer part selected, displaying the contents of "truncated number" in the IBM RPA Studio console with Log Message.
defVar --name truncatedNumber --type Numeric
truncateNumber --value 8.9 --type "IntegerPart" truncatedNumber=value
logMessage --message "${truncatedNumber}" --type "Info"
// 8
Example 2: A numeric variable called- "truncated number" - is defined, which receives the result of the truncation of the number 8.9 with the parameter Decimal part selected without checking the option Decimal as integer. The contents of "truncated number" are displayed in the IBM RPA Studio console with Log Message.
defVar --name truncatedNumber --type Numeric
truncateNumber --value 8.9 --type "DecimalPart" truncatedNumber=value
logMessage --message "${truncatedNumber}" --type "Info"
// 0.9