Convert 60 seconds to 1:00(minutes to secons) -
AmirRFCNR - 10.10.2014
how to convert count down seconds to minutes
Example:
instead of 80 seconds show player contdown like this 1:20
i have this
pawn Код:
format(string, sizeof(string), "~w~TIME LEFT~n~~r~%d", PrisonTime[i]);
Re: Convert 60 seconds to 1:00(minutes to secons) -
SKAzini - 10.10.2014
https://sampforum.blast.hk/showthread.php?tid=192514#3
A little searching doesn't hurt.
Respuesta: Convert 60 seconds to 1:00(minutes to secons) -
SickAttack - 10.10.2014
pawn Код:
stock ConvertToMinutes(time)
{
new string[10], minutes, seconds;
if(time > 59)
{
minutes = floatround(time / 60);
seconds = floatround(time - minutes * 60);
format(string, sizeof(string), "%02d:%02d", minutes, seconds);
}
else
{
seconds = floatround(time);
format(string, sizeof(string), "00:%02d", seconds);
}
return string;
}
pawn Код:
format(string, sizeof(string), "~w~TIME LEFT~n~~r~%d", ConvertToMinutes(PrisonTime[i]));
Re: Convert 60 seconds to 1:00(minutes to secons) -
kirostar - 10.10.2014
https://sampforum.blast.hk/showthread.php?tid=192514
Search first then post
Re: Convert 60 seconds to 1:00(minutes to secons) -
SKAzini - 10.10.2014
Quote:
Originally Posted by kirostar
|
Interesting people in this community..
Quote:
Originally Posted by SickAttack
pawn Код:
stock ConvertToMinutes(time) { new string[10], minutes, seconds; if(time > 59) { minutes = floatround(time / 60); seconds = floatround(time - minutes * 60); format(string, sizeof(string), "%02d:%02d", minutes, seconds); } else { seconds = floatround(time); format(string, sizeof(string), "00:%02d", seconds); } return string; }
|
Small improvement:
pawn Код:
ConvertToMinutes(time)
{
new string[10], minutes, seconds;
minutes = floatround(time / 60);
seconds = floatround(time - minutes * 60);
format(string, sizeof(string), "%02d:%02d", minutes, seconds);
return string;
}
You don't need an if check there..
Respuesta: Re: Convert 60 seconds to 1:00(minutes to secons) -
SickAttack - 10.10.2014
Quote:
Originally Posted by SKAzini
Interesting people in this community..
Small improvement:
pawn Код:
ConvertToMinutes(time) { new string[10], minutes, seconds; minutes = floatround(time / 60); seconds = floatround(time - minutes * 60); format(string, sizeof(string), "%02d:%02d", minutes, seconds); return string; }
You don't need an if check there..
|
I made it like that for a reason. If he doesn't like the format he could change it easily without making a new thread, which I assumed he would.
Re: Convert 60 seconds to 1:00(minutes to secons) -
Threshold - 11.10.2014
Assuming 'time' is in seconds, this is all you need:
pawn Код:
ConvertToMinutes(time)
{
new string[10], minutes = 0;
while(time >= 60) minutes++, time -= 60;
format(string, sizeof(string), "%02d:%02d", minutes, time);
return string;
}
Re: Convert 60 seconds to 1:00(minutes to secons) -
Vince - 11.10.2014
Quote:
Originally Posted by SKAzini
Small improvement:
pawn Код:
ConvertToMinutes(time) { new string[10], minutes, seconds; minutes = floatround(time / 60); seconds = floatround(time - minutes * 60); format(string, sizeof(string), "%02d:%02d", minutes, seconds); return string; }
You don't need an if check there..
|
I still think this is the best solution. Except you can remove floatround as well. An integer divided by an integer yields an integer. Any decimals that would've come out in a "normal" calculation are simply dropped. Assuming our example from before, 330 / 60 would yield simply 5.
Re: Convert 60 seconds to 1:00(minutes to secons) -
Shady - 11.10.2014
Search before post.
Re: Convert 60 seconds to 1:00(minutes to secons) -
AmirRFCNR - 11.10.2014
Quote:
Originally Posted by SKAzini
|
https://sampforum.blast.hk/showthread.php?tid=192514
Quote:
Originally Posted by kirostar
Search first then post
|
i did but i hade errors in this code, now i changed %d to %s and work fine
thanks all