Converting Numbers into Strings

Complete the following steps to convert a number into a string using the Format Into String function.

  1. Add a numeric control to the front panel window.

     Add  Find
  2. Add a string indicator to the front panel window.

     Add  Find
  3. Add the Format Into String function to the block diagram.

     Add  Find
  4. Right-click the Format Into String function and select Edit Format String from the shortcut menu to display the format string in the Edit Format String dialog box. Use this dialog box to create the format string, which specifies the format, precision, data type, and width of the converted value.
    1. From the Selected operation pull-down menu, select Format fractional number.
    2. Select Right justify from the Justification pull-down menu and Pad using zeros from the Padding pull-down menu.
    3. Place a checkmark in the Use minimum field width checkbox in the Options section and type 8. Press the <Enter> key. The Corresponding format string field should now contain %08f. If you enter a number in the numeric control with less than 8 digits, this entry pads the remaining spaces with zeros before the first digit.
    4. Place a checkmark in the Use specified precision checkbox in the Options section and type 4. Press the <Enter> key. The Corresponding format string field should now contain %08.4f. This entry converts the number in the numeric control into a string with four digits after the decimal point.
    5. Click the OK button. The function creates a string constant and wires it to the format string input.
  5. Wire the numeric control you created in step 1 to the input 1 input of the Format Into String function.
  6. Wire the string indicator you created in step 2 to the resulting string output of the Format Into String function.
  7. Return to the front panel and run the VI. Notice that the string indicator displays a number with four decimal places.

You also can use the String/Number Conversion functions to convert between numeric and string representations.