Help me
#1

Hello guys , i have a little question for you :

How can i make a Integer who is > 1000 to appear me 1,000 or if it's 1232344 for example it appear 1.232.344 ! sorry for my really bad english , so i left a code down there ... maybe see what i say ..

Код HTML:
new String[128];
format(String, sizeof(String), "Hello, you have {008000}$%i{FFFFFF} !", GetPlayerMoney(playerid));
SendClientMessage(playerid, -1, String);
And i want message to look like those message [depends of money]:

Hello, you have $3.496 ! ==> means $3496
Hello, you have $232.127 ! ==> means $232127
Hello, you have $3.232.566 ! ==> means $3232566
Hello, you have $232.232.566 ! ==> means $232232566
Hello, you have $1.032.232.566 ! ==> means $1032232566

I think you understand what i try to explain with my very bad english o.O
Reply
#2

Quote:
Originally Posted by Mariciuc223
Посмотреть сообщение
Hello guys , i have a little question for you :

How can i make a Integer who is > 1000 to appear me 1,000 or if it's 1232344 for example it appear 1.232.344 ! sorry for my really bad english , so i left a code down there ... maybe see what i say ..

Код HTML:
new String[128];
format(String, sizeof(String), "Hello, you have {008000}$%i{FFFFFF} !", GetPlayerMoney(playerid));
SendClientMessage(playerid, -1, String);
And i want message to look like those message [depends of money]:

Hello, you have $3.496 ! ==> means $3496
Hello, you have $232.127 ! ==> means $232127
Hello, you have $3.232.566 ! ==> means $3232566
Hello, you have $232.232.566 ! ==> means $232232566
Hello, you have $1.032.232.566 ! ==> means $1032232566

I think you understand what i try to explain with my very bad english o.O
This is for max 1.000.000, you can do the rest yourself I hope, else unfortunate, couldnt bother doing it for higher amounts.
PHP код:
new sAmount[64], sConvert[64], sA[64], sB[64], iMoniez;
iMoniez GetPlayerMoney(playerid);
format(sAmountsizeof(sAmount), "%d"iMoniez);
if (
iMoniez >= 1000 && iMoniez 1000000)
{
    
strmid(sAsAmount0strlen(sAmount)-3);
    
strmid(sBsAmountstrlen(sAmount)-3strlen(sAmount));
    
format(sConvertsizeof(sConvert), "%s.%s"sAsB);
    return 
1;

sConvert will be the amount of money thats convert from for example 950000 to 950.000, its in string format.
Reply
#3

I made this up for you... haven't really optimized it at all but it works with any value

PHP код:

stock formatMoney
amount,output[64],delimiter[2]=","){
    
format(outputsizeof(output), "%i"amount );
    if(
strlen(output) > 3){
        for(new 
0= (strlen(output)/3); j;  i++){
            
strins(outputdelimiterstrlen(output)-(((i+1)*3)+i) );
        }
    }
}
// usage
new money 59329192;
new 
str[64];
formatMoney(moneystr"." );
printf(str); // Prints 59.329.192
formatMoney(moneystr );
print(
str); // Prints 59,329,192 
Reply
#4

Quote:
Originally Posted by !damo!spiderman
Посмотреть сообщение
I made this up for you... haven't really optimized it at all but it works with any value

PHP код:

stock formatMoney
amount,output[64],delimiter[2]=","){
    
format(outputsizeof(output), "%i"amount );
    if(
strlen(output) > 3){
        for(new 
0= (strlen(output)/3); j;  i++){
            
strins(outputdelimiterstrlen(output)-(((i+1)*3)+i) );
        }
    }
}
// usage
new money 59329192;
new 
str[64];
formatMoney(moneystr"." );
printf(str); // Prints 59.329.192
formatMoney(moneystr );
print(
str); // Prints 59,329,192 
Nice, I havent gave a though to do it like this. Better than mine wich is manually for every dot. :P
Reply
#5

pawn Код:
stock NiceNumber(iNum, const szChar[] = ",")
{
    new
        szStr[16]
    ;
    format(szStr, sizeof(szStr), "%d", iNum);

    for(new iLen = strlen(szStr) - 3; iLen > 0; iLen -= 3)
    {
        strins(szStr, szChar, iLen);
    }
    return szStr;
}
pawn Код:
NiceNumber(12345)

Will output: 12,345 for example
pawn Код:
format(str,sizeof(str),"This is how much it is: %s",NiceNumber(12345));
str will output: This is how much it is: 12,345
Reply
#6

Quote:
Originally Posted by liquor
Посмотреть сообщение
pawn Код:
stock NiceNumber(iNum, const szChar[] = ",")
{
    new
        szStr[16]
    ;
    format(szStr, sizeof(szStr), "%d", iNum);

    for(new iLen = strlen(szStr) - 3; iLen > 0; iLen -= 3)
    {
        strins(szStr, szChar, iLen);
    }
    return szStr;
}


pawn Код:
NiceNumber(12345)

Will output: 12,345 for example
pawn Код:
format(str,sizeof(str),"This is how much it is: %d",NiceNumber(12345));
str will output: This is how much it is: 12,345
Yours is much nicer than mine... my pawn is about 7 years rusty, didn't even think you could return arrays in functions
Reply
#7

Quote:
Originally Posted by !damo!spiderman
Посмотреть сообщение
Yours is much nicer than mine... my pawn is about 7 years rusty, didn't even think you could return arrays in functions
Oh, i made a mistake, it does output a string due to the delimeter ','.. but still. Just use %s instead of %d
Reply
#8

@OP, you may want to look into this include as well: formatnumber.inc.
Reply
#9

I gave to all +Rep .. Thx all for the help and i have a new question , how can i check if a player enter in te inputtext a message like that : [DD/MM/YYYY] ? I need it to save player birthday xD [Am thx for replay so fast]

Quote:
Originally Posted by !damo!spiderman
Посмотреть сообщение
I made this up for you... haven't really optimized it at all but it works with any value

PHP код:

stock formatMoney
amount,output[64],delimiter[2]=","){
    
format(outputsizeof(output), "%i"amount );
    if(
strlen(output) > 3){
        for(new 
0= (strlen(output)/3); j;  i++){
            
strins(outputdelimiterstrlen(output)-(((i+1)*3)+i) );
        }
    }
}
// usage
new money 59329192;
new 
str[64];
formatMoney(moneystr"." );
printf(str); // Prints 59.329.192
formatMoney(moneystr );
print(
str); // Prints 59,329,192 
Or i can simple modify

Код HTML:
stock formatMoney( amount,output[64],delimiter[2]=","){
in
Код HTML:
stock formatMoney( amount,output[64],delimiter[2]="."){
and use like this

Код HTML:
new String[64];
formatMoney(GetPlayerMoney(playerid), String)
And i don't need to put "."
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)