RoundRealToNearestInteger
- Updated2023-02-21
- 1 minute(s) read
RoundRealToNearestInteger
long RoundRealToNearestInteger (double realNumber);
Purpose
Rounds its floating-point argument and returns the result as a long integer. Using the round-half-even algorithm, also known as banker's rounding, the function rounds a value with a fractional part of exactly 0.5 to the nearest even number.
Example Code
long n;
n = RoundRealToNearestInteger (1.2); /* result: 1L */
n = RoundRealToNearestInteger (1.8); /* result: 2L */
n = RoundRealToNearestInteger (1.5); /* result: 2L */
n = RoundRealToNearestInteger (0.5); /* result: 0L */
n = RoundRealToNearestInteger (-1.2); /* result: -1L */
n = RoundRealToNearestInteger (-1.8); /* result: -2L */
n = RoundRealToNearestInteger (-1.5); /* result: -2L */
n = RoundRealToNearestInteger (-0.5); /* result: 0L */
Parameters
Input | ||
Name | Type | Description |
realNumber | double | Real number to round. |
Return Value
Name | Type | Description |
nearestInteger | long | The integer nearest to the value of the real number. |
Additional Information
Library: Utility Library
Include file: utility.h
LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later