Adding a 0 to a one-digit in a timer - 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: Adding a 0 to a one-digit in a timer (
/showthread.php?tid=637288)
Adding a 0 to a one-digit in a timer -
Amit1998 - 12.07.2017
Hi,
I'm trying to use the following code to add a 0 if the digit is below 10, but it doesnt appear on the textdraw:
Код:
new wh_alert_seconds[2], wh_seconds[2];
if(seconds < 10) format(wh_seconds, sizeof(wh_seconds), "0%d", seconds); else format(wh_seconds, sizeof(wh_seconds), "%d", seconds);
if(alert_seconds < 10) format(wh_alert_seconds, sizeof(wh_alert_seconds), "0%d", alert_seconds); else format(wh_alert_seconds, sizeof(wh_alert_seconds), "%d", alert_seconds);
Any tip?
Thanks.
Re: Adding a 0 to a one-digit in a timer -
Paulice - 12.07.2017
No if-then/else required:
PHP код:
format(wh_seconds, sizeof(wh_seconds), "%02d", seconds);
format(wh_alert_seconds, sizeof(wh_alert_seconds), "%02d", alert_seconds);
Re: Adding a 0 to a one-digit in a timer -
Abagail - 12.07.2017
Is there a specific reason you're storing those as strings and not as integers?
Re: Adding a 0 to a one-digit in a timer -
Paulice - 12.07.2017
Quote:
Originally Posted by Abagail
Is there a specific reason you're storing those as strings and not as integers?
|
He wants to use them as the TextDraws' text.
[ ----- ]
PHP код:
new wh_alert_seconds[2], wh_seconds[2];
I just noticed those, set the cell amount to 3 if you want up to a two digit number.