Converting a String to an Integer Using LabVIEW Mathscript Node

Updated Oct 15, 2020

Reported In


  • LabVIEW MathScript Module
  • LabVIEW

Issue Details

I am using the MathScript Node in LabVIEW and I'm trying to convert a string into an integer. However, the str_to_num function is returning a complex double data type.


Note: NI does not recommend LabVIEW MathScript Module functions for new designs. See for information and recommended alternatives.

You can convert a string into an integer by using a combination of type conversion functions in the MathScript node, as shown below:
string = '1986'
real_number = real(str_to_num(string))
real_integer = int16(real_number(1))
Below is a screenshot of what this would look like in LabVIEW.

Additional Information

  • str_to_num returns a 1-dimensional (1D) complex double array with one element, the converted numeric value of string
  • real returns the real portion of the complex double array into a real double-precision 1D array with one element
  • int16 converts the double-precision value of its input, which is the first element of real_number
  • The value of real_integer is now a signed 16-bit integer, 1986
LabVIEW determines the data types of MathScript Node variables during edit-time, and automatically selects the smallest data type that encompasses all possible values of the variable. Since it is possible that a string would contain a complex double-precision number, that is the data type that the str_to_num and str_to_double functions return by default.

For more detailed information on data types and string to numeric conversions in the LabVIEW Mathscript Node, please refer to the Related Links below.