To number action
- Updated: 2022/11/23
To number action
The To number action in the String package enables you to convert a string to a number.
Settings
This action supports positive, negative, and decimal numbers.
Note: If the
string contains commas, remove them by using the
Replace
action to replace each comma with an empty
string.
- In the Enter the string field, specify the source string.
- In the Assign the output to variable field, specify the number variable.
Example
Create a bot to convert a string to a
decimal number.
- Create a bot.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: String_to_number.
- Click Create and Edit.
- On the left panel, click Automation.
- To assign the string to a variable, double-click or drag the
action.
- In the Select the source string variable(s)/value field, select 5.78.
- In the Select the source string variable(s)/ value (optional) field, click the Create variable icon to create a variable.
- On the Create variable window, enter stringtest in the Name field.
- Click Create and select.
- To convert string to a number, double-click or drag the
action.
- In the Enter the string field, select $string_test$ variable.
- In the Assign the output to variable field, click the Create variable icon to create a variable.
- On the Create variable window, enter numtest in the Name field.
- Click Create and select.
- To print the values, double-click or drag the Message box action. In the Enter the message to display field, enter $numtest.Number:toString$.
- Click Save and then
Run.
You now observe that the bot truncates the values after the decimal points and displays the output as 5. Hence, you must again convert this number value to a string value to generate an output that would include the value with the decimal point.
- To convert the number to a string, from the Actions pane, double-click or drag the
action.
- In the Enter a number field, select $numtest$ variable.
- In the Enter number of digits after decimal (number format) field, enter 3.
- In the Assign the output to variable field, click the Create variable icon to create a variable.
- On the Create variable window, enter numtostring_output in the Name field.
- Click Create and select.
- To print the values, double-click or drag the Message box action. In the Enter the message to display field, enter $numtostring_output$.
- Click Save and then
Run.
The bot now displays the value as 5.78.