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.
  1. Create a bot.
    1. On the left panel, click Automation.

      A list of available bots and forms is displayed.

    2. Click Create a bot.
    3. Enter the bot name: String_to_number.
    4. Click Create and Edit.
  2. To assign the string to a variable, double-click or drag the String > Assign action.
    1. In the Select the source string variable(s)/value field, select 5.78.
    2. In the Select the source string variable(s)/ value (optional) field, click the Create variable icon to create a variable.
    3. On the Create variable window, enter stringtest in the Name field.
    4. Click Create and select.
  3. To convert string to a number, double-click or drag the String > To number action.
    1. In the Enter the string field, select $string_test$ variable.
    2. In the Assign the output to variable field, click the Create variable icon to create a variable.
    3. On the Create variable window, enter numtest in the Name field.
    4. Click Create and select.
  4. To print the values, double-click or drag the Message box action. In the Enter the message to display field, enter $numtest.Number:toString$.
  5. 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.

  6. To convert the number to a string, from the Actions pane, double-click or drag the Number > To string action.
    1. In the Enter a number field, select $numtest$ variable.
    2. In the Enter number of digits after decimal (number format) field, enter 3.
    3. In the Assign the output to variable field, click the Create variable icon to create a variable.
    4. On the Create variable window, enter numtostring_output in the Name field.
    5. Click Create and select.
  7. To print the values, double-click or drag the Message box action. In the Enter the message to display field, enter $numtostring_output$.
  8. Click Save and then Run.

    The bot now displays the value as 5.78.

    Convert string to a decimal number