parseInt

The parseInt task parses a string value and returns an integer (number) value using the decimal number system as a mathematical base. Only the first number in the string is returned. If the string argument is not a string, it is converted to a string using the ToString abstract operation. Leading whitespace in the string is ignored.

Potential use case

This task is useful when you need to convert a number represented as a string into an integer. For example, if your data string contains a decimal value such as "1.655", parseInt will convert the decimal value to the rounded number 1, and the digits that follow the decimal will be truncated.

Properties

InputTypeDescription
strStringRequired. The string value to parse and return as a number.
radixNumberOptional. Represents the numerical system used to convert str to an integer. This can be a value between 2 and 36. If no radix is provided, the default will be 10 (decimal).
OutputTypeDescription
resultNumberThe number that returns when the input str is parsed. If the first character cannot be converted to a number, the result returns NaN.

Example 1

In this example:

  • The incoming string variable str is statically set to 0xF, which is a hexadecimal representation.
  • The radix number is set to 16, which is a hexadecimal number.
parseInt task with str 0xF and radix 16

The result of the outgoing variable is 15.

parseInt task output showing result 15

Example 2

In this example:

  • The incoming string variable str is statically set to 02019 4 29. Notice the white spaces within the reference variable.
  • No radix number is provided, so the default decimal value (10) is used.
parseInt task with str 02019 4 29 and no radix provided

The result of the outgoing variable is 2019.

parseInt task output showing result 2019

Example 3

In this example:

  • The incoming string variable str is statically set to 5.99.
  • No radix number is provided, so the default decimal value (10) is used.
parseInt task with str 5.99 and no radix provided

The result of the outgoing variable is 5. The numbers after the decimal are truncated.

parseInt task output showing result 5 with decimal truncated

Example 4

In this example:

  • The incoming string variable str is statically set to 7,123. Notice the value contains a comma.
  • No radix number is provided, so the default decimal value (10) is used.
parseInt task with str 7,123 containing a comma

The result of the outgoing variable is 7. The numbers after the comma are truncated.

parseInt task output showing result 7 with digits after comma truncated

Example 5

In this example:

  • The incoming string variable str is set to 20*4. Notice the operator (asterisk) within the reference variable.
  • No radix number is provided, so the default decimal value (10) is used.
parseInt task with str 20*4 containing an asterisk operator

The result of the outgoing variable is 20.

parseInt task output showing result 20