{"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","replaced_by":[],"games":[{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},{"game":"ofpe","name":"Operation Flashpoint: Elite","version":"1.00"},{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"ofp","name":"Operation Flashpoint","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Remainder of *a* divided by *b*.","syntaxes":[{"syntax":"a % b","since":null,"effect":null,"exec":null,"params":[{"name":"a","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"a: Number"},{"name":"b","type":"Number","optional":false,"default":null,"description":null,"types":["Number"],"since":null,"text":"b: Number"}],"returns":{"type":"Number","types":["Number"],"description":null,"text":"Number"},"form":"binary","operator":"%","left":{"text":"a","types":["Number"]},"right":{"text":"b","types":["Number"]}}],"examples":[{"text":"```sqf\n4.5 % 3 // result is 1.5\n```","code":["4.5 % 3 // result is 1.5"]}],"multiplayer":null,"problems":null,"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\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```"}],"categories":["ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Math","Introduced with Operation Flashpoint version 1.00","Operation Flashpoint: Elite: Scripting Commands","Operation Flashpoint: New Scripting Commands","Operation Flashpoint: Scripting Commands","Scripting Commands","Take On Helicopters: Scripting Commands"]}