CINT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
Tags: Undo Reverted
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The [[CINT]] function rounds decimal point numbers up or down to the nearest [[INTEGER]] value.
The [[CINT]] function rounds decimal point numbers up or down to the nearest [[INTEGER]] value.




Line 6: Line 6:




{{Parameters}}
{{PageParameters}}
* {{Parameter|expression}} is any [[TYPE]] of literal or variable numerical value or mathematical calculation.
* {{Parameter|expression}} is any [[TYPE]] of literal or variable numerical value or mathematical calculation.


Line 12: Line 12:
{{PageDescription}}
{{PageDescription}}
* Values greater than .5 are rounded up. Values lower than .5 are rounded down.
* Values greater than .5 are rounded up. Values lower than .5 are rounded down.
* ''Warning:'' Since [[CINT]] is used for integer values, the input values cannot exceed 32767 to -32768!  
* ''Warning:'' Since [[CINT]] is used for integer values, the input values cannot exceed 32767 to -32768!
* Use [[CLNG]] for [[LONG]] integer values exceeding [[INTEGER]] limitations.
* Use [[CLNG]] for [[LONG]] integer values exceeding [[INTEGER]] limitations.
* Note: When decimal point values are given to BASIC functions requiring [[INTEGER]]s the value will be [[CINT]]ed.
* Note: When decimal point values are given to BASIC functions requiring [[INTEGER]]s the value will be [[CINT]]ed.
Line 18: Line 18:


{{PageExamples}}
{{PageExamples}}
''Example:'' Shows how CINT rounds values up or down as in "bankers' rounding".  
''Example:'' Shows how CINT rounds values up or down as in "bankers' rounding".
{{CodeStart}} '' ''
{{CodeStart}}
a% = {{Cl|CINT}}(1.49): b% = {{Cl|CINT}}(1.50): c = 11.5
a% = {{Cl|CINT}}(1.49): b% = {{Cl|CINT}}(1.50): c = 11.5
{{Cl|COLOR}} c: {{Cl|PRINT}} a%, b%, c '' ''
{{Cl|COLOR}} c: {{Cl|PRINT}} a%, b%, c
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}{{text|1      2      11.5|red}}
{{OutputStart}}{{Text|1      2      11.5|red}}
{{OutputEnd}}
{{OutputEnd}}



Latest revision as of 22:17, 11 February 2023

The CINT function rounds decimal point numbers up or down to the nearest INTEGER value.


Syntax

value% = CINT(expression)


Parameters

  • expression is any TYPE of literal or variable numerical value or mathematical calculation.


Description

  • Values greater than .5 are rounded up. Values lower than .5 are rounded down.
  • Warning: Since CINT is used for integer values, the input values cannot exceed 32767 to -32768!
  • Use CLNG for LONG integer values exceeding INTEGER limitations.
  • Note: When decimal point values are given to BASIC functions requiring INTEGERs the value will be CINTed.


Examples

Example: Shows how CINT rounds values up or down as in "bankers' rounding".

a% = CINT(1.49): b% = CINT(1.50): c = 11.5
COLOR c: PRINT a%, b%, c
1       2       11.5


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link