Obtain Numbers After the Decimal Point as Integers With LabVIEW

Updated Apr 29, 2021



  • LabVIEW

This article shows how to obtain the numbers after the decimal point as integers of a numeric value using LabVIEW. This article assumes that you have basic knowledge about numeric data types and operations.

There is not a predefined function in LabVIEW that gets the numbers after the decimal point so there is some programming that needs to be done in order to get these numbers as integers. This article covers two basic approaches to process the number and get the desired output:

Converting the number to a string for processing:
1. Wire the numeric value into the input string of the Format Into String Function which will format the numeric value into a string with the specified format.
2. Specify the format of the output string to have a set amount of decimal point numbers. The '.16f' modifier in the format string input gives a 16 digit format to the number and the '#' modifier eliminates the trailing zeros.
3. Wire the converted string to the input string of the Scan From String Function which will scan for the string and display the outputs according to the expected format.
4. Place an indicator in the second output terminal to obtain the number after the decimal point as an integer.

The resulting code should look something like this:
option 1.png

Without converting the number to string
1. Place the Quotient & Remainder Function in the block diagram and wire the numeric value to the x terminal and a constant of 1 to the y terminal. This function computes the integer quotient and the remainder of the inputs.
2. The remainder needs to be multiplied by 10^x where x is the number of the decimal places of the original number. You can do this by using the Power Of 10 Function and wiring the decimal places (precision) to the x terminal.
3. Convert the output of the Multiply VI to an integer and place an indicator to show the value.

The resulting code should look something like this:
option 2.png