Originally Posted by Mастерминд
Long long time ago, I made a function.. and the time has come to release it.
pawn Код:
stock DecimalPoint(money) { new str[16]; if(money >= 0) { format(str, sizeof(str), "$%d", money); if(1000 <= money < 10000) strins(str, ".", 2, sizeof(str)); else if(10000 <= money < 100000) strins(str, ".", 3, sizeof(str)); else if(100000 <= money < 1000000) strins(str, ".", 4, sizeof(str)); else if(1000000 <= money < 10000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); } else if(10000000 <= money < 100000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); } else if(100000000 <= money < 1000000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); } else if(money >= 1000000000) { strins(str, ".", 2, sizeof(str)); strins(str, ".", 6, sizeof(str)); strins(str, ".", 10, sizeof(str)); } } else { format(str, sizeof(str), "-$%d", money-(money*2)); if(-1000 >= money > -10000) strins(str, ".", 3, sizeof(str)); else if(-10000 >= money > -100000) strins(str, ".", 4, sizeof(str)); else if(-100000 >= money > -1000000) strins(str, ".", 5, sizeof(str)); else if(-1000000 >= money > -10000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); } else if(-10000000 >= money > -100000000) { strins(str, ".", 4, sizeof(str)); strins(str, ".", 8, sizeof(str)); } else if(-100000000 >= money > -1000000000) { strins(str, ".", 5, sizeof(str)); strins(str, ".", 9, sizeof(str)); } else if(money <= -1000000000) { strins(str, ".", 3, sizeof(str)); strins(str, ".", 7, sizeof(str)); strins(str, ".", 11, sizeof(str));} } return str; }
Usage:
pawn Код:
new str[40]; format(str, sizeof(str), "Your money: %s.", DecimalPoint(GetPlayerMoney(playerid))); SendClientMessage(playerid, WHITE, str);
(Note: it returns a string, so it must always be %s)
The max string it returns is -$2.147.483.647 (16 cells).
..I made that function real long time ago, when I was a beginner
|