Il contenuto non è disponibile nella lingua selezionata.

Verrà mostrato il contenuto in un'altra delle lingue disponibili. Il tuo browser potrebbe avere delle funzionalità di traduzione.

LabVIEW Standard for Rounding Numbers

Updated Nov 14, 2017

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

What is the standard for rounding numbers in LabVIEW?

Solution

When a floating-point number is converted to an integer, it is rounded to the nearest integer. The only exception to this are numbers exactly halfway between two integers, such as 2.5, 3.5, etc. In this case, the number is rounded to the nearest even integer. For example, 2.5 would be rounded to 2, and 3.5 would be rounded to 4. This is consistent with the IEEE Standard 754.

Additional Information

The reason that LabVIEW uses this convention is based on statistical analysis. If a large group of random numbers are rounded by rounding up on .5, there is a statistical error that is introduced. By using the odd/even convention, that error is reduced based on the fact that out of a large group of random numbers, there is usually a close ratio of odd and even numbers. If that ratio is exactly 1:1, then the error is eliminated completely. For example, if you add 4.5 and 5.5 together, the result is 10. If you round those to the nearest integer using the round up on .5 method and then add, the answer is 11. But, if you use the odd/even convention and then add, the answer is 10. Using the round up on .5 convention in this example introduces a 10% error.

This way of thinking only applies to random numbers. If the number set is more likely to have odd or even numbers, then a different convention must be used to reduce rounding errors. If this is the case, manually round the numbers before the Round to Nearest function or coercion dot. This can be accomplished by using the Round to + Infinity function to have .5 rounded up, or use the Round to - Infinity function to have .5 rounded down.