- 18 Oct 2024
-
DarkLight
-
PDF
numberToString
- Updated on 18 Oct 2024
-
DarkLight
-
PDF
numberToString Task Purpose
The numberToString task is used to convert a number to a string. Based on the optional radix
parameter, the output returns a string that represents the specified number object. This task method is the opposite of the parseInt task used to convert a string value to a number. Lastly, the numberToString task does not change the value of the original number.
The radix
specifies the number of unique digits in the numeral system, including 0. For example, a radix of 10 would represent the Decimal system because the Decimal system uses ten digits from 0 through 9. Whereas, a radix of 2 would represent the Binary system because the Binary system uses only two digits which are 0 and 1. A radix of 8 represents the Octal system, and a radix of 16 represents the Hexadecimal system.
Potential Use Cases
Sometimes you may need to construct a string that contains a number from another variable. You could potentially use this task to handle a field of numerical data that needs to be converted to a string first before exporting to a text file. Moreover, let's say you have implemented specific calculations and wish to display the computed numbers as text in a financial statement. To do this, you could use numberToString and convert the numbers to a string.
Properties
Input and output properties are shown below.
Input | Type | Description |
---|---|---|
num |
Number | Required. |
radix |
Number | Optional. A number in the range of 2 through 36 specifying the mathematical base to use for representing a numeric value. If no radix is provided, the default will be 10 (a decimal number). |
Output | Type | Description |
---|---|---|
numToString |
String | A string representing the specified number object. |
Example 1
In this IAP example, the incoming num
variable is statically set to 255
and the radix
number is omitted, so the default will be a decimal number (10).
The numToString
value that returns in the outgoing variable is "255"
. Notice the number is a literal string enclosed within double quotation marks.
Example 2
In this IAP example, the radix
of 2 represents the Binary system, which means the num
variable of 255
will be converted to a Binary number.
The numToString
value that returns is "11111111"
.
Example 3
With this example the radix
of 8 represents the Octal system, which means the num
variable of 255
will be converted to an Octal.
The numToString
value that returns is "377"
.
Example 4
With this example the radix
of 16 represents the Hexidecimal system, which means the num
variable of 255
will be converted to a Hexidecimal number.
The numToString
value that returns is "ff"
.