[REP++] Formating long numbers
#1

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?
Reply
#2

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

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)); 
Reply
#4

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

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;

Reply
#6

It works. Thank you very much!
Reply
#7

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

//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 
Reply
#9

Thanks again
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)