{"name":"a % b","operator":"%","title":"a % b","type":"command","url":"https://community.bistudio.com/wiki/a_%25_b","revid":318435,"updated":"2022-05-13T07:44:52Z","groups":["Math"],"status":"ok","games":{"ofp":"1.00","ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofp 1.00","arma3_since":"0.50","description":"Remainder of *a* divided by *b*.","syntaxes":[{"syntax":"a % b","params":[{"name":"a","type":"Number","type_expr":"Number"},{"name":"b","type":"Number","type_expr":"Number"}],"returns":{"type":"Number","type_expr":"Number"},"form":"binary","left":{"text":"a"},"right":{"text":"b"}}],"examples":[{"code":["4.5 % 3 // result is 1.5"]}],"aliases":["mod"],"see_also":["mod","Operators"],"notes":[{"user":"Hoz","date":"2006-04-16T01:34:00Z","text":"- Remainder is calculated in real domain.\n- a % b is identical to mod\n\nYou 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:\n\n```sqf\n_rand = random 6;\n_num = _rand - (_rand % 1);\n```\n\nIn A1, the new commands round, floor or ceil would be the easier way to round."},{"user":"SilentSpike","date":"2015-07-21T14:55:00Z","text":"Be careful when dealing with negative numbers. The way a modulo operation treats negatives differs between languages. In SQF truncated division is used, hence:\n\n```sqf\n-12 % -10 = -2\n-12 %  10 = -2\n 12 % -10 =  2\n 12 %  10 =  2\n```"}]}