SA-MP Forums Archive
[REP++] Formating long numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [REP++] Formating long numbers (/showthread.php?tid=602615)



[REP++] Formating long numbers - AdmBot - 10.03.2016

Hi! I've modified the include made by AbyssMorgan (for unsigned long variables) and i have some issues formating long numbers.

I've tried with strval, but doesn't work for long number. I think the solutin is to make a function to format string (as numbers).
Ex: for 250000000000 show 250,000,000,000 but not working for number upper 1,450,000,000. Could anyone help me?


Re: [REP++] Formating long numbers - Amunra - 10.03.2016

https://sampforum.blast.hk/showthread.php?tid=598933
Includes


Re: [REP++] Formating long numbers - AbyssMorgan - 10.03.2016

PHP код:
new buffer[64];
GetLYString(250,999,buffer);
printf("Value: %s",buffer); // print 250000000999 
//Commas can add modifying buffer
format(buffer,sizeof buffer,"%s",AddCommasLY(buffer)); 



Re: [REP++] Formating long numbers - AdmBot - 10.03.2016

How can i modify the buffer, i need to use commas.


Re: [REP++] Formating long numbers - AbyssMorgan - 10.03.2016

PHP код:
 stock AddCommasLY(string[]){
new 
tStr[32];
format(tStr,sizeof(tStr),"%s",string);
    if(
strlen(tStr) < 4) return tStr;
    new 
iPos strlen(tStr), iCount 1;
    while(
iPos 0)
    {
    if(
iCount == 4)
    {
        
iCount 0;
        
strins(tStr,",",iPos,1);
            
iPos++;
        }
        
iCount++;
        
iPos--;
    }
    return 
tStr;




Re: [REP++] Formating long numbers - AdmBot - 10.03.2016

It works. Thank you very much!


Re: [REP++] Formating long numbers - AdmBot - 12.03.2016

@AbyssMorgan, another problem: I want to calculate the bank interest using this long number. You can i do this?


Re: [REP++] Formating long numbers - AbyssMorgan - 12.03.2016

//edit: to improve it did not work exactly

Update LY.inc and use
PHP код:
CalculatePercentLY(&prefix,&suffix,Float:percent 0.0,increase true,limitprefix DEFAULT_MAX_LY_PREFIX
Download:
LY.inc

Example:

PHP код:
new abc[LY_STRING_LEN];
250;
999999999;
//input: 250 999 999 999
CalculatePercentLY(a,b,10.0,true);
GetLYString(a,b,c);
printf(c); //Output: 276 099 999 999 



Re: [REP++] Formating long numbers - AdmBot - 12.03.2016

Thanks again