Convert 60 seconds to 1:00(minutes to secons)
#1

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]);
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=192514#3

A little searching doesn't hurt.
Reply
#3

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]));
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=192514

Search first then post
Reply
#5

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..
Reply
#6

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.
Reply
#7

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;
}
Reply
#8

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.
Reply
#9

Search before post.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)