Formatting number. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Formatting number. (
/showthread.php?tid=565302)
Formatting number. -
HY - 26.02.2015
Hello.
As title says, I have a question.
How could I format a number as '0000'.
For example. I create a Textdraw, and player have 185 $. I want to format number to be: 000000185, for example.
How can I do that?
Thanks.
Re: Formatting number. -
Schneider - 26.02.2015
%09d
Will give a number with 9 digits.
for example:
pawn Код:
new number = 312;
new str[24];
format(str, sizeof(str), "Number: %08d", number);
print(str);
..will print: "Number: 00000312"
The same method + a period . works of the amount of decimals in floats.
"%.1f" will limit the amout of decimals to 1 (i.e: 5.13983 will become 5.1)
Re: Formatting number. -
Banana_Ghost - 26.02.2015
You can format it by replacing %d or %i with %08d of %08i.
Edit, above poster was faster, even more detailed.
Re: Formatting number. -
HY - 26.02.2015
Quote:
Originally Posted by Banana_Ghost
You can format it by replacing %d or %i with %08d of %08i.
Edit, above poster was faster, even more detailed.
|
Quote:
Originally Posted by Schneider
%09d
Will give a number with 9 digits.
for example:
pawn Код:
new number = 312; new str[24]; format(str, sizeof(str), "Number: %08d", number); print(str);
..will print: "Number: 00000312"
|
Thanks, both.