Arma 3 Scripting

a % b

  • Arma 3 v0.50
  • First in Operation Flashpoint v1.00
  • Alias of mod

Command · Markdown · JSON · original wiki page

Description

Remainder of a divided by b.

Syntax

a % b

Parameters:

Returns: Number

Examples

Example 1

4.5 % 3 // result is 1.5

See also

mod · Operators

Community notes

Hoz

  • Remainder is calculated in real domain.
  • a % b is identical to mod You can use % to round a decimal number down to the nearest whole number. For example: If you wanted to use the command random to generate a whole number between 0 and 5, you could put this in a script:
_rand = random 6;
_num = _rand - (_rand % 1);

In A1, the new commands round, floor or ceil would be the easier way to round.

SilentSpike

Be careful when dealing with negative numbers. The way a modulo operation treats negatives differs between languages. In SQF truncated division is used, hence:

-12 % -10 = -2
-12 %  10 = -2
 12 % -10 =  2
 12 %  10 =  2