ROUND: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
mNo edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_ROUND}} | {{DISPLAYTITLE:_ROUND}} | ||
The [[_ROUND]] function rounds to the closest | The [[_ROUND]] function rounds to the closest [[INTEGER]], [[LONG]] or [[_INTEGER64]] numerical value. (If the value ends with .5, it rounds instead to the closest EVEN integer value.) | ||
Line 10: | Line 10: | ||
* Can round [[SINGLE]], [[DOUBLE]] or [[_FLOAT]] floating decimal point parameter values. | * Can round [[SINGLE]], [[DOUBLE]] or [[_FLOAT]] floating decimal point parameter values. | ||
* Can be used when numerical values exceed the limits of [[CINT]] or [[CLNG]]. | * Can be used when numerical values exceed the limits of [[CINT]] or [[CLNG]]. | ||
* | * If the number to be rounded is less than 0.5, then it rounds down to the closest integer value. | ||
* If the number to be rounded is greater than 0.5, then it rounds up to the closest integer value. | |||
* If the number to be rounded ends in 0.5, rounding is done to the closest even integer value. | |||
Line 20: | Line 22: | ||
{{Cl|PRINT}} {{Cl|_ROUND}}(3.5) | {{Cl|PRINT}} {{Cl|_ROUND}}(3.5) | ||
{{Cl|PRINT}} {{Cl|_ROUND}}(4.5) | {{Cl|PRINT}} {{Cl|_ROUND}}(4.5) | ||
{{Cl|PRINT}} {{Cl|_ROUND}}(5.5) | {{Cl|PRINT}} {{Cl|_ROUND}}(5.5) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}0 | {{OutputStart}}0 | ||
Line 31: | Line 33: | ||
{{PageSeeAlso}} | |||
* [[INT]], [[CINT]] | * [[INT]], [[CINT]] | ||
* [[FIX]], [[CLNG]] | * [[FIX]], [[CLNG]] |
Latest revision as of 18:25, 5 May 2025
The _ROUND function rounds to the closest INTEGER, LONG or _INTEGER64 numerical value. (If the value ends with .5, it rounds instead to the closest EVEN integer value.)
Syntax
- value = _ROUND(number)
Description
- Can round SINGLE, DOUBLE or _FLOAT floating decimal point parameter values.
- Can be used when numerical values exceed the limits of CINT or CLNG.
- If the number to be rounded is less than 0.5, then it rounds down to the closest integer value.
- If the number to be rounded is greater than 0.5, then it rounds up to the closest integer value.
- If the number to be rounded ends in 0.5, rounding is done to the closest even integer value.
Example: Displays how QB64 rounds to the closest even integer value.
PRINT _ROUND(0.5) PRINT _ROUND(1.5) PRINT _ROUND(2.5) PRINT _ROUND(3.5) PRINT _ROUND(4.5) PRINT _ROUND(5.5) |
0 2 2 4 4 6 |
See also