M1ke_SK 230 Posted April 23, 2017 I have number as string. I want to add zeroes to number. Example: "1" => "001", "11" => "011" Any slick function for that? Possibly without some loop. _number = "11"; for "_i" from (count _number) to 2 do { _number = "0" + _number; }; Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted April 23, 2017 Why no loop though? TAG_fnc_fillNumber = { params [["_digits",3],["_number","1"]]; _count = count _number; _difference = _digits - _count; if (_count < _digits) then { _toAdd = ""; for "_i" from 1 to _difference do { _toAdd = _toAdd + "0"; }; (_toAdd + _number) }; }; _test = [3,"1"] call TAG_fnc_fillNumber; systemchat str _test; // "001" _test = [6,"11"] call TAG_fnc_fillNumber; systemchat str _test; // "000011" Cheers Share this post Link to post Share on other sites
M1ke_SK 230 Posted April 23, 2017 Maybe some solution: Add x number of "0" before number and trim last 3 digits. Example: "11" > "000000000011" > "011" Share this post Link to post Share on other sites
Grumpy Old Man 3540 Posted April 23, 2017 How would that be any different from my solution? Anything wrong about for "_i" that I don't know about? Does it not do what you requested in the first post? Cheers Share this post Link to post Share on other sites
killzone_kid 1326 Posted April 23, 2017 _paddingZeroes = "0000000000"; _formatTotalLength = 5; _number = "123"; _result = (_paddingZeroes select [0, _formatTotalLength - count _number]) + _number; // "00123" 2 Share this post Link to post Share on other sites
M1ke_SK 230 Posted April 23, 2017 15 minutes ago, killzone_kid said: _paddingZeroes = "0000000000"; _formatTotalLength = 5; _number = "123"; _result = (_paddingZeroes select [0, _formatTotalLength - count _number]) + _number; // "00123" Yes, that I was talking about. The mighty select function :D Share this post Link to post Share on other sites