Originally Posted by Skream
Formato seguindo o padrгo R$
pawn Код:
stock formatReal(Float:amount) { new rmoney[22] = "R$";
format(rmoney, sizeof(rmoney), "R$%0.2f", amount > 0 ? (amount) : (-amount));
new l = strlen(rmoney);
rmoney[l - 3] = ',';
l -= 3;
while((l -= 3) > 2) { strins(rmoney, ".", l); } if(amount < 0) { strins(rmoney, "-", 0); } return rmoney; }
outputs:
pawn Код:
main() { printf("%s", formatReal(100.30)); printf("%s", formatReal(1000.30)); printf("%s", formatReal(10000.30)); printf("%s", formatReal(100000.30)); printf("%s", formatReal(1000000.52)); printf("%s", formatReal(-100.30)); printf("%s", formatReal(-1000.30)); printf("%s", formatReal(-10000.30)); printf("%s", formatReal(-100000.30)); printf("%s", formatReal(-1000000.52)); }
[19:26:30] R$100,30 [19:26:30] R$1.000,29 [19:26:30] R$10.000,29 [19:26:30] R$100.000,29 [19:26:30] R$1.000.000,50 [19:26:30] -R$100,30 [19:26:30] -R$1.000,29 [19:26:30] -R$10.000,29 [19:26:30] -R$100.000,29 [19:26:30] -R$1.000.000,50
essa versгo eu uso apenas para ints e com a strlib:
pawn Код:
stock formatReal(amount) { new rmoney[22] = "R$"; strcat(rmoney, ret_valstr(amount)); strcat(rmoney, ",00");
new l = strlen(rmoney) - 3; while((l -= 3) > 2) { strins(rmoney, ".", l); } if(amount < 0) { strins(rmoney, "-", 0); } return rmoney; }
|