Example Code

Rounding Numbers After the Decimal Place To A Specific Number Of Places

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example demonstrates how to round a number after the decimal point to a specific number of places.

 

Description

This example code allows the user to round numbers after the decimal place by treating these numbers as integers. For example, assume the user starts with the number 54.345 and wanted to round this number two places after the decimal point. This example would multiply the number by 10^2 to move the decimal two places to the right. The "Round to Nearest" function is then used to round 5434.5 to the nearest integer resulting in 5435. The code will then divide 5435 by 10^2 to move the decimal back to the left by two places. This results in the number 54.35.

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached VI
  2. Run the program

 

Additional Information or References

Rounding Numbers After The Decimal Place - Front Panel.png

 

Rounding Numbers After The Decimal Place - Block Diagram.png

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Todd S.
NI Employee (retired)
on

Thanks for posting.  Could you please rename your attachment to include the LabVIEW version?

Todd S.
LabVIEW Community Manager
National Instruments