Jump to content
Sign in to follow this  
jw custom

Displaying 7+ digit numbers?

Recommended Posts

cash = 1000000;

hint format["%1",cash];

The output is: 1E+006

With 6 digits 100000 it display the string fine. How do i get it to display the proper value with 7 digits?

Share this post


Link to post
Share on other sites

Well you could always try string manipulation to "break down" the number into parts of 6 digits each (using /, floor and mod) but of course something that just gets the conversion of number->string differently in the firstplace would be better if possible. I wouldn't be surprised if there is no elegant solution, though, as I also remember running into issues when trying to store large values into variables (maybe because the engine wouldn't convert the numbers back from string to number when they have too many digits).

Edited by galzohar

Share this post


Link to post
Share on other sites
Well you could always try string manipulation to "break down" the number into parts of 6 digits each (using /, floor and mod)

When i try that my brain starts to burn :eek:

I guess i have to lower my prices :p

Share this post


Link to post
Share on other sites

Or you could just string it, ie "10000000".

str(10000000)

Might work.

Share this post


Link to post
Share on other sites

Try this, note the code is for testing as it is but describes the principal, basically finds how many mill you have and adds that to the remainder which is the sub one million component. You will get the odd rounding difference at times, though at over one mill I doubt you will count the old dollars out. You could place the conversion in an if statement to only proceed when the amount is above a mill.

nul = [] spawn 
{
_num1= 19876543;
hint format [ "%1", _num1];
_NumMills = _num1/1000000 -  (_num1/1000000 mod 1);
_Remainder = _num1 mod 1000000;
sleep 4;
hint format ["%1%2",_NumMills,_Remainder];
};

Share this post


Link to post
Share on other sites
Or you could just string it, ie "10000000".

str(10000000)

Might work.

Already tried that and it didnt work, but thanks for your reply :)

Try this, note the code is for testing as it is but describes the principal, basically finds how many mill you have and adds that to the remainder which is the sub one million component. You will get the odd rounding difference at times, though at over one mill I doubt you will count the old dollars out. You could place the conversion in an if statement to only proceed when the amount is above a mill.

nul = [] spawn 
{
_num1= 19876543;
hint format [ "%1", _num1];
_NumMills = _num1/1000000 -  (_num1/1000000 mod 1);
_Remainder = _num1 mod 1000000;
sleep 4;
hint format ["%1%2",_NumMills,_Remainder];
};

I tried messing a little around with it but as usually my head are about to explode :p

If my value using your example is 1075000 i end up with 175000 :o

I guess i just have to use lower numbers, but thanks for your help :)

Share this post


Link to post
Share on other sites

Ok i managed to get it working for my purpose using blakeace example:

_num1 = 1000000;

_numMills = _num1/1000000 - (_num1/1000000 mod 1);

_remainder = _num1 mod 1000000;

if (_numMills > 0 && _remainder < 100000 && _remainder > 10000) then {

if (_numMills == 1) then {_numMills = 10};

if (_numMills == 2) then {_numMills = 20};

if (_numMills == 3) then {_numMills = 30};

if (_numMills == 4) then {_numMills = 40};

if (_numMills == 5) then {_numMills = 50};

if (_numMills == 6) then {_numMills = 60};

if (_numMills == 7) then {_numMills = 70};

if (_numMills == 8) then {_numMills = 80};

if (_numMills == 9) then {_numMills = 90};

};

if (_numMills > 0 && _remainder < 10000 && _remainder > 1) then {

if (_numMills == 1) then {_numMills = 100};

if (_numMills == 2) then {_numMills = 200};

if (_numMills == 3) then {_numMills = 300};

if (_numMills == 4) then {_numMills = 400};

if (_numMills == 5) then {_numMills = 500};

if (_numMills == 6) then {_numMills = 600};

if (_numMills == 7) then {_numMills = 700};

if (_numMills == 8) then {_numMills = 800};

if (_numMills == 9) then {_numMills = 900};

};

if (_numMills > 0 && _remainder < 1) then {

if (_numMills == 1) then {_numMills = 100000};

if (_numMills == 2) then {_numMills = 200000};

if (_numMills == 3) then {_numMills = 300000};

if (_numMills == 4) then {_numMills = 400000};

if (_numMills == 5) then {_numMills = 500000};

if (_numMills == 6) then {_numMills = 600000};

if (_numMills == 7) then {_numMills = 700000};

if (_numMills == 8) then {_numMills = 800000};

if (_numMills == 9) then {_numMills = 900000};

};

if(_numMills > 0) then {

hint format ["%1%2",_numMills,_remainder];

} else {

hint format ["%1",_remainder];

};

Thanks for your example :)

P.S. if someone comes up with a proper calculation then please share :)

Edited by JW Custom

Share this post


Link to post
Share on other sites

I tried writing something for you but apparently it doesn't work because the game doesn't even save that many digits and just seems to round the numbers.

_number = _this select 0; // the number you want to print
_numString = "";
while {_number>0} do
{
_addedNum = _number mod 1000000;
_addedString = str _addedNum;
if (_number>=1000000) then
{
	if (_addedNum > 0) then
	{
		while {_addedNum < 100000} do
		{
			_addedNum = _addedNum * 10;
			_addedString = "0" + _addedString;
		};
	}
	else
	{
		_addedString = "000000";
	};
};
_numString = _addedString + _numString;
_number = floor (_number / 1000000);
};

That was supposed to work but seems to have some kind of rounding errors issues even when the number is just 123456789 (but it does work with 12345678). So for very large numbers you will have to make up and implement your own variable type...

Edited by galzohar

Share this post


Link to post
Share on other sites

Edited, seems to work now. You'll have to handle fractions yourself though, as this only works for whole numbers. Then again fractions shouldn't be that hard to implement, you just need to handle the first digit + the fraction first and then use the script for the rest of the number.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×