08.07.2016, 17:46
Let's say I've a number with the value of 600, how I can make a string that would show it as 10:00? (600 seconds = 10 minutes)
stock ConvertTime(vreme)
{
new minuti, sekunde, string[128];
if(vreme > 59)
{
minuti = floatround(vreme/60);
sekunde = floatround(vreme - minuti*60);
if(sekunde > 9) format(string, sizeof(string), "%d:%d", minuti, sekunde);
else format(string, sizeof(string), "%d:0%d", minuti, sekunde);
}
else
{
sekunde = floatround(vreme);
if(sekunde > 9) format(string, sizeof(string), "0:%d", sekunde);
else format(string, sizeof(string), "0:0%d", sekunde);
}
return string;
}
here u go a function:
PHP код:
|
ConvertTime(seconds)
{
new string[10];
format(string, sizeof string, "%02i:%02i", (seconds / 60) % 60, seconds % 60);
return string;
}
here u go a function:
PHP код:
|
stock SecToMin(value)
{
new sec = value%60,
min = Euclideandiv(value, 60),
str[30];
format(str, sizeof(str), "%02i:%02i", min, sec);
return str;
}
stock Euclideandiv(dividende, diviseur, &reste = 0)
{
new
result = 0;
for(; dividende >= diviseur; result++)
dividende -= diviseur;
reste = dividende;
return result;
}