- 18 Oct 2024
-
DarkLight
-
PDF
parseint (number)
- Updated on 18 Oct 2024
-
DarkLight
-
PDF
parseInt Task Purpose
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, then it is converted to a string (using the ToString abstract operation). Leading whitespaces in the string are ignored.
Potential Use Case
This task is useful when you need to convert a number represented as a string into an integer. Let's say your data string contains a decimal value such as "1.655". With parseInt, the decimal value will convert to the rounded number '1', and the digits that follow the decimal will be truncated.
Properties
Input and output properties are shown below.
Input | Type | Description |
---|---|---|
str |
String | Required. The string value to parse and return as a number. |
radix |
Number | Optional. Represents the numerical system used to convert str to an integer. This can be a value between 2 and 36. Note: If no radix is provided, the default will be 10 (decimal). |
Output | Type | Description |
---|---|---|
result |
Number | The 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 the IAP example shown below:
-
The incoming string variable
str
is statically set to0xF
, which is a hexidecimal representation. -
The
radix
number is set to16
, which is a hexidecimal number. -
The
result
of the outgoing variable is15
.
Example 2
In the IAP example shown below:
-
The incoming string variable
str
is statically set to02019 4 29
. Notice the white spaces within the reference variable. -
No
radix
number is provided, so the default decimal value (10) is used. -
The
result
of the outgoing variable is2019
.
Example 3
In the IAP example shown below:
-
The incoming string variable
str
is statically set to5.99
. -
No
radix
number is provided, so the default decimal value (10) is used. -
The
result
of the outgoing variable is5
. The numbers after the decimal are truncated.
Example 4
In the IAP example shown below:
-
The incoming string variable
str
is statically set to7,123
. Notice the value for the reference variable contains a comma. -
No
radix
number is provided, so the default decimal value (10) is used. -
The
result
of the outgoing variable is7
. The numbers after the comma are truncated.
Example 5
In the IAP example shown below:
-
The incoming string variable
str
is set to20*4
. Notice the operator (asterik) within the reference variable. -
No
radix
number is provided, so the default decimal value (10) is used. -
The
result
of the outgoing variable is20
.