Help me -
Mariciuc223 - 15.07.2015
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
Re: Help me ++REP -
notime - 15.07.2015
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(sAmount, sizeof(sAmount), "%d", iMoniez);
if (iMoniez >= 1000 && iMoniez < 1000000)
{
strmid(sA, sAmount, 0, strlen(sAmount)-3);
strmid(sB, sAmount, strlen(sAmount)-3, strlen(sAmount));
format(sConvert, sizeof(sConvert), "%s.%s", sA, sB);
return 1;
}
sConvert will be the amount of money thats convert from for example 950000 to 950.000, its in string format.
Re: Help me ++REP -
!damo!spiderman - 15.07.2015
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(output, sizeof(output), "%i", amount );
if(strlen(output) > 3){
for(new i = 0, j = (strlen(output)/3); i < j; i++){
strins(output, delimiter, strlen(output)-(((i+1)*3)+i) );
}
}
}
// usage
new money = 59329192;
new str[64];
formatMoney(money, str, "." );
printf(str); // Prints 59.329.192
formatMoney(money, str );
print(str); // Prints 59,329,192
Re: Help me ++REP -
notime - 15.07.2015
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(output, sizeof(output), "%i", amount );
if(strlen(output) > 3){
for(new i = 0, j = (strlen(output)/3); i < j; i++){
strins(output, delimiter, strlen(output)-(((i+1)*3)+i) );
}
}
}
// usage
new money = 59329192;
new str[64];
formatMoney(money, str, "." );
printf(str); // Prints 59.329.192
formatMoney(money, str );
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
Re: Help me -
liquor - 15.07.2015
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
Re: Help me -
!damo!spiderman - 15.07.2015
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
Re: Help me -
liquor - 15.07.2015
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
Re: Help me -
Virtual1ty - 15.07.2015
@OP, you may want to look into this include as well:
formatnumber.inc.
Re: Help me -
Mariciuc223 - 15.07.2015
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(output, sizeof(output), "%i", amount );
if(strlen(output) > 3){
for(new i = 0, j = (strlen(output)/3); i < j; i++){
strins(output, delimiter, strlen(output)-(((i+1)*3)+i) );
}
}
}
// usage
new money = 59329192;
new str[64];
formatMoney(money, str, "." );
printf(str); // Prints 59.329.192
formatMoney(money, str );
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 "."