Convert Value Operator: Convert Number to a String

Overview

You'll use the Convert Value operator to change a single data type into another. Data types include strings, integers, and numbers. In this article, you'll learn how to convert individual number values into strings. The easiest way to tell if your number converted to a string is the quotation marks around your output. You'll set up a Number component for this use case and enter and submit a number in Express View.

Before you begin, there's a couple of things to consider when converting numbers to strings:

  • Decimal points in your number will also appear in your string output.

  • Numbers with commas appear as text to the Number component, and it won't accept them. An example would be 1,000,000.

  • Succeeding zeros in your number will disappear after the conversion. For instance, the number 125.500 converts to the string "125.5".

Here's how your module will look in the Module Builder:

Here's how the completed use case will look in Express View, including a peek at the DevTools Console:

What You'll Learn

In this article, you'll learn how to use the Convert Value operator to convert a number to a string.

What You'll Need

To set up this use case, you’ll need:

  • 1 Number component

  • 1 Hidden component

  • 1 Data Workflow component

  • 1 Button component

To set up your Data Workflow, you'll need:

  • 1 Input operator

  • 1 Convert Value operator

  • 1 Output operator

  • 2 Console operators

NOTE  These instructions assume you have a new module open, saved, and with a title.

Configuration

Configure the Number Component

First, you'll set up a Number component so your end-user can enter a number to convert to a string.

1. In the Module Builder, drag and drop a Number component onto your canvas.
2. Enter numberInput in the Property ID field.
3. Enter Number Input in the Label Text field.
4. Enter Enter a Number in the Helper Text field.
5. Click Save.

Configure the Hidden Component

Next, you'll configure a Hidden component to hold your Data Workflow's output.

1. Drag and a Hidden component onto your canvas, placing it below your Number component.
2. Enter stringOutput as the Property ID and Canvas Label Text fields.
3. Click Save.

Configure the Data Workflow Component

Now, it's time to set up your Data Workflow. First, you'll input your Number component into a Convert Value operator. Then you'll cast any number entered in the Number field to a string. This new string then outputs to your Hidden component. To watch your Data Workflow's progress, you'll also configure 2 Console operators.

1. Drag and drop a Data Workflow component onto your canvas. Place your Data Workflow below your Hidden component.
2. Enter dwfConvertValueString in the Canvas Label Text and Property Name fields.

Configure the Input Operator

1. Drag and drop an Input operator onto your Data Workflow canvas.
2. Configure the Input operator's Info window as follows:
Setting Value

Category

Input

Component

numberInput

Required

No

Source

Default

Configure the Convert Value Operator

1. Drag and drop a Convert Value operator onto your Data Workflow canvas.
2. Configure the Convert Value operator's Info window as follows:
Setting Value

Category

Convert To Value

Label

Convert to String

Cast To

String

3. Connect the output port (right) of the Input operator to the input port (left) of the Convert Value operator.

Configure the Output Operator

1. Drag and drop an Output operator onto your Data Workflow canvas.
2. Configure the Output operator's Info window as follows:
Setting Value

Category

Output

Component

stringOutput

Action

value

3. Connect the output port (right) of the Convert Value operator to the input port (left) of the Output operator.

Configure the First Console Operator

1. Drag and drop a Console operator onto your Data Workflow canvas.
2. Configure the Console operator's Info window as follows:
Setting Value

Category

Console

Label

Number Input

3. Connect the output port (right) of the Input operator to the input port (left) of the Number Input Console operator.

Configure the Second Console Operator

1. Drag and drop another Console operator onto your Data Workflow canvas.
2. Configure the Console operator's Info window as follows:
Setting Value

Category

Console

Label

String Output

3. Connect the output port (right) of the Convert Value operator to the input port (left) of the String Output Console operator.

Configure the Button Component

Now, let's add a Button component to trigger your Data Workflow.

1. Drag and drop a Button component onto your canvas, placing it below your Data Workflow.
2. Enter btnConvertToString in the Property ID field.
3. Enter Convert Number to String in the Label field.
4. Select Event as the Action Type.
5. Enter dwfConvertValueString in the Trigger on Click field.

6. Click Save.
7. Save your module.

Now you can test out your Data Workflow. Preview your module in Express View. Enter a number like 325.50 into the Number field and click your button. The Number Input Console shows your number as you entered it. After passing through the operator, the String Output Console shows the converted string. You'll see that the operator added quotation marks around your string "325.5".

Lab

You can view this complete use case here: https://training.unqork.io/#/form/606352847fd9a1023dfd57fa/edit.