String to Number Conversion Functions
There are four built-in
string to number conversion functions in LabVIEW that convert string input data to its associated
numeric output data types:
Determining which of these built-in functions you should use depends on your input data type. Below is an example of how to use one of these built-in functions.
Fract/Exp String To Number Function
The
Fract/Exp String to Number function works well if you are using numbers containing decimal points or those using exponential values, but can also be used for integers. This method is available in LabVIEW 6.0 and later.
- On your LabVIEW block diagram, add the Fract/Exp String to Number function (Functions Palette » String » String/Number Conversion)
- Right-click the number output node and select Create Indicator.
- Right-click on the numeric indicator and select Properties.
- Navigate to the Display Format tab to configure your preferred output formatting.
5. Optional: If on your local system, a decimal separation is indicated by a comma, set the use system decimal point to true as seen in the snippet below.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW block diagram
Scan from String Function
Other than the standard built-in String/Number conversation functions, you can also use the
Scan from String function to convert string data into multiple data types including binary integers, SI numbers, and
timestamps . This method is available in LabVIEW 5.0 and later.
- On the LabVIEW block diagram, add the Scan from String function (Functions Palette » String).
- Right-click on the function and select Edit Scan String.
- Select the appropriate data type from the Selected operation drop-down menu that matches the data type of your input string.
- Customize the string format using the Corresponding scan string textbox. This tells the function what to look for in the input string and should match the format of the input string.
- Use Format Specifier Syntax as guidance in setting the scan string format.
- Tip: The pattern for specifying the decimal separator is the percent sign followed by the decimal separator you choose followed by a semi-colon. Which is %,;%f for the comma case as seen in the snippet below.
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW block diagram