How to: Convert a Number to an Integer

Prev Next

The Convert Value operator is used 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 integers.

Before you begin, there are a couple of considerations to make when converting numbers to integers:

  • If you enter a number with a decimal, the Convert Value operator removes it and every number to the right of it. For example, if you convert 12.345, the output is 12.

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

Configuration

In this how-to guide, you'll set up a Number component so an end-user can enter a number to be converted. Then, you’ll set up a Data Workflow component with a Convert Value operator to manipulate the value.

Configure the Number Component

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

  1. In the Module Builder, drag and drop a Number component onto your canvas.

  2. In the Property ID field, enter numberInput.

  3. In the Label Text field, enter Number Input.

  4. In the Helper Text field, enter Enter a Number.

  5. Click Save Component.

Configure the Hidden Component

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

  1. Drag and a Hidden component onto your canvas, placing it below your numberInput Number component.

  2. In the Property ID and Label Text fields, enter integerOutput.

  3. Click Save Component.

Configure the Data Workflow Component

Now, it's time to set up your Data Workflow. First, you'll bring your Number component data into the Data Workflow using an Input operator. Then, you’ll pass that data to the Convert Value operator and cast any number entered in the Number field to an integer. Then, output the new integer to your Hidden component. You'll also configure two Console operators to view the progress in the DevTools Console.

  1. Drag and drop a Data Workflow component onto your canvas, placing it below your Hidden component.

  2. In the Property ID and Canvas Label Text fields, enter dwfConvertValueInteger.

Configure the Input Operator

  1. Drag and drop an Input operator onto your Data Workflow canvas.

  2. Configure the 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 operator's Info window as follows:

    Setting

    Value

    Category

    Convert To Value

    Label

    Convert to Integer

    Cast To

    Integer

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

Configure the Output Operator

  1. Drag and drop an Output operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Output

    Component

    integerOutput

    Action

    value

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

Configure the First Console Operator

  1. Drag and drop a Console operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Number Input

  3. Connect the output port (right) of the numberInput 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Integer Output

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

    Workflow diagram illustrating data conversion from input to integer output.

  4. Click Save Component.

Configure the Button Component

Lastly, 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 dwfConvertValueInteger Data Workflow.

  2. In the Property ID field, enter btnConvertToInteger .

  3. In the Label Text field, enter Convert Number to Integer .

  4. Set the Action Type drop-down, select Event.

  5. Under Triggers, in the On Click drop-down, select dwfConvertValueInteger.

  6. Click Save.

  7. Save your module.

Here's how your completed module looks in the Module Builder:

Input field for number conversion with output display and conversion button.

Preview your module in Express View and open the DevTools Console. Enter a number, like 250.25, into the Number field. Click the Convert Number to Integer button. The Number Input Console displays your number as you entered it. After passing through the Convert Value operator, the Integer Output Console displays the converted integer. You'll see that the operator removed the decimal point and the numbers to the right of it, leaving 250.

User interface showing number input and conversion to integer output in a console.

The Convert Value operator is used 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 integers.

Before you begin, there are a couple of considerations to make when converting numbers to integers:

  • If you enter a number with a decimal, the Convert Value operator removes it and every number to the right of it. For example, if you convert 12.345, the output is 12.

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

Configuration

In this how-to guide, you'll set up a Number component so an end-user can enter a number to be converted. Then, you’ll set up a Data Workflow component with a Convert Value operator to manipulate the value.

Configure the Number Component

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

  1. In the Module Builder, drag and drop a Number component onto your canvas.

  2. In the Property ID field, enter numberInput.

  3. In the Label Text field, enter Number Input.

  4. In the Helper Text field, enter Enter a Number.

  5. Click Save.

Configure the Hidden Component

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

  1. Drag and a Hidden component onto your canvas, placing it below your numberInput Number component.

  2. In the Property ID and Canvas Label Text fields, enter integerOutput.

  3. Click Save.

Configure the Data Workflow Component

Now, it's time to set up your Data Workflow. First, you'll bring your Number component data into the Data Workflow using an Input operator. Then, you’ll pass that data to the Convert Value operator and cast any number entered in the Number field to an integer. Then, output the new integer to your Hidden component. You'll also configure two Console operators to view the progress in the DevTools Console.

  1. Drag and drop a Data Workflow component onto your canvas, placing it below your Hidden component.

  2. In the Canvas Label Text and Property Name fields, enter dwfConvertValueInteger.

Configure the Input Operator

  1. Drag and drop an Input operator onto your Data Workflow canvas.

  2. Configure the 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 operator's Info window as follows:

    Setting

    Value

    Category

    Convert To Value

    Label

    Convert to Integer

    Cast To

    Integer

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

Configure the Output Operator

  1. Drag and drop an Output operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Output

    Component

    integerOutput

    Action

    value

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

Configure the First Console Operator

  1. Drag and drop a Console operator onto your Data Workflow canvas.

  2. Configure the operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Number Input

  3. Connect the output port (right) of the numberInput 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 operator's Info window as follows:

    Setting

    Value

    Category

    Console

    Label

    Integer Output

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

    Workflow diagram illustrating data conversion from input to integer output.

  4. Click Save.

Configure the Button Component

Lastly, 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 component.

  2. In the Property ID field, enter btnConvertToInteger.

  3. In the Label Text field, enter Convert Number to Integer.

  4. Set Action Type as Event.

  5. From the On Click drop-down, select dwfConvertValueInteger.

    Button configuration settings for converting numbers to integers in a workflow.

  6. Click Save.

  7. Save your module.

Here's how your completed module looks in the Module Builder:

Module editor displaying number input and conversion button for integer values.

Preview your module in Express View and open the DevTools Console. Enter a number, like 250.25, into the Number field. Click the Convert Number to Integer button. The Number Input Console displays your number as you entered it. After passing through the Convert Value operator, the Integer Output Console displays the converted integer. You'll see that the operator removed the decimal point and the numbers to the right of it, leaving 250.

User interface showing number input and conversion to integer output in a console.