Skip to content

Commit

Permalink
Merge pull request #214 from CBATeam/fixNegativeFormatNumberDecimals
Browse files Browse the repository at this point in the history
Fix FormatNumber Decimals with Negative Numbers
  • Loading branch information
Killswitch00 committed Dec 11, 2015
2 parents b3ec002 + 72f8ec0 commit f2f0149
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/strings/fnc_formatNumber.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ if (_number < 0) then {
if (_decimalPlaces > 0) then {
private ["_digit", "_multiplier", "_i"];

//Use abs to prevent extra `-` signs and so floor doesn't get wrong value
_number = abs _number;

_string = _string + _decimalPoint;

_multiplier = 10;
Expand Down
6 changes: 6 additions & 0 deletions addons/strings/test_strings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ TEST_OP(_str,==,"012",_fn);
_str = [-12] call CBA_fnc_formatNumber;
TEST_OP(_str,==,"-12",_fn);

_str = [-12.75] call CBA_fnc_formatNumber;
TEST_OP(_str,==,"-13",_fn);

_str = [-12.75,0,3] call CBA_fnc_formatNumber;
TEST_OP(_str,==,"-12.750",_fn);

// ----------------------------------------------------------------------------
// UNIT TESTS (elaspsedTime)
_fn = "CBA_fnc_formatElapsedTime";
Expand Down

0 comments on commit f2f0149

Please sign in to comment.