ACE3/addons/common/functions/fnc_numberToDigits.sqf
2015-05-14 20:06:06 +02:00

40 lines
808 B
Plaintext

/*
* Author: commy2
*
* Transforms a number to an array of the correspondending digits.
*
* Argument:
* 0: Number to 'digitize' (Number)
* 1: Set the minimal length of the returned array. Useful for getting left hand zeroes. (Number, optional)
*
* Return value:
* Digits. The maximum count is six digits. (Array)
*/
#include "script_component.hpp"
private ["_length", "_digits"];
PARAMS_2(_number,_minLength);
_number = _number min 999999;
_number = str _number;
_length = count _number;
if (isNil "_minLength") then {_minLength = _length};
_minLength = _minLength min 6;
while {_length < _minLength} do {
_number = "0" + _number;
_length = _length + 1;
};
_digits = [];
for "_x" from 0 to (_length - 1) do {
_digits pushBack parseNumber (_number select [_x, 1]);
};
_digits