\: Difference between revisions
Jump to navigation
Jump to search
Created page with "The '''\''' mathematical operator performs INTEGER division on a numerical value. {{PageSyntax}} ::: return_value = number '''\''' divisor {{PageDescription}} * Number value can be any literal or variable numerical type. * '''Divisor (second value) must not be a value of 0 to .5'''. This will create a "Division by zero" error! due to CINT rounding. * Return values will be INTEGER or LONG value types only. * Rounding is done to the..." |
mNo edit summary |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
The | The [[\]] mathematical operator performs [[INTEGER]] division on a numerical value. | ||
{{PageSyntax}} | |||
{{PageSyntax}} | : {{Parameter|return_value}} = {{Parameter|number}} [[\]] {{Parameter|divisor}} | ||
: | |||
{{PageDescription}} | {{PageDescription}} | ||
* Number value can be any literal or variable numerical type. | * Number value can be any literal or variable numerical type. | ||
* '''Divisor (second value) must not be a value of 0 to .5'''. This will create a [[ERROR Codes|"Division by zero" error!]] due to [[CINT]] rounding. | * '''Divisor (second value) must not be a value of -0.5 to .5'''. This will create a [[ERROR Codes|"Division by zero" error!]] due to [[CINT]] rounding. | ||
* Return values will be [[INTEGER]] or [[LONG]] value types only. | * Return values will be [[INTEGER]] or [[LONG]] value types only. | ||
* Rounding is done to the | * Rounding of the result is always done as with INT(x / y) and is always rounded down. | ||
* Use the [[/]] | * The numerator and denominator will be rounded via CINT, CLNG, or _ROUND to the corresponding integer value if they're floating point values and not native integers. | ||
* Division and multiplication operations are performed before addition and subtraction in | * Use the [[/|/ normal division]] operator for floating point return values. | ||
* Division and multiplication operations are performed before addition and subtraction in QBasic's order of operations. | |||
{{PageExamples}} | |||
{{CodeStart}} | ;Example:Displays how floating decimal point values are rounded to the closest even [[INTEGER|integer]] value. | ||
{{CodeStart}} | |||
{{Cl|PRINT}} 0.5 \ 1 | {{Cl|PRINT}} 0.5 \ 1 | ||
{{Cl|PRINT}} 1.5 \ 1 | {{Cl|PRINT}} 1.5 \ 1 | ||
Line 25: | Line 24: | ||
{{Cl|PRINT}} 3.5 \ 1 | {{Cl|PRINT}} 3.5 \ 1 | ||
{{Cl|PRINT}} 4.5 \ 1 | {{Cl|PRINT}} 4.5 \ 1 | ||
{{Cl|PRINT}} 5.5 \ 1 | {{Cl|PRINT}} 5.5 \ 1 | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}0 | {{OutputStart}}0 | ||
Line 36: | Line 35: | ||
{{PageSeeAlso}} | |||
* [ | * [https://qb64phoenix.com/forum/showthread.php?tid=3661 Featured in our "Keyword of the Day" series] | ||
* [[Mathematical Operations]] | * [[Mathematical Operations]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 18:34, 5 May 2025
The \ mathematical operator performs INTEGER division on a numerical value.
Syntax
- return_value = number \ divisor
Description
- Number value can be any literal or variable numerical type.
- Divisor (second value) must not be a value of -0.5 to .5. This will create a "Division by zero" error! due to CINT rounding.
- Return values will be INTEGER or LONG value types only.
- Rounding of the result is always done as with INT(x / y) and is always rounded down.
- The numerator and denominator will be rounded via CINT, CLNG, or _ROUND to the corresponding integer value if they're floating point values and not native integers.
- Use the / normal division operator for floating point return values.
- Division and multiplication operations are performed before addition and subtraction in QBasic's order of operations.
Examples
- Example
- Displays how floating decimal point values are rounded to the closest even integer value.
PRINT 0.5 \ 1 PRINT 1.5 \ 1 PRINT 2.5 \ 1 PRINT 3.5 \ 1 PRINT 4.5 \ 1 PRINT 5.5 \ 1 |
0 2 2 4 4 6 |
See also