Converting Float Value to Hours, Days, Months -
Tayab - 11.01.2014
What I am trying to achieve is that I will have a really big float value which basically will be months converted to milliseconds and from that I want to make hours, days and months.
Example.
pawn Код:
pInfo[playerid][VIPTime] = 1000*60*60*24*30.4368; // setting VIP for 1 month.
Now with that how can I pull out how many hours, days and months will it be?
I'll provide any other additional information needed. Any helper will be given a +rep.
Re: Converting Float Value to Hours, Days, Months -
Hansrutger - 12.01.2014
You need to check what month it is (getdate) with an if-statement, if the month is 1, 5, 7, 8, 10, 12: then it has 31 days. If it's 2, it got 28 days. And rest it got 30 days. Of course each 4th year it also has 29 days on February. Is this system worth it? No. Set your VIP system to be 30 days instead, just like every other game has. World of Wacraft has 60-days game card for a reason. Everything has a meaning and that is why bigger game companies use months, but days to count "special treatment" and even punishments. They never use months, only days or years because they are much easier to calculate by hand.
Anyways you want to convert 30 days now into milliseconds:
30 * 24 * 60 * 60 * 1000. Float needed? Nope. ;P
To calculate how many hours you just use the formula backwards and stop which you want to calculate:
days * hours * minutes * seconds * milliseconds
If you want seconds you take and you have milliseconds, you just do
Код:
seconds = miniseconds / 1000;
Want hours?
Код:
hours = milliseconds / (hours*minutes*seconds*milliseconds)
It will use an implicit way to convert the formula into an integer, will convert downwards automatically.
Re: Converting Float Value to Hours, Days, Months -
Tayab - 12.01.2014
Quote:
Originally Posted by Hansrutger
Want hours?
Код:
hours = milliseconds / (hours*minutes*seconds*milliseconds)
|
This part kinda went off my head. Can you elaborate it please?
Re: Converting Float Value to Hours, Days, Months -
Hansrutger - 12.01.2014
Let's say you have 18.000.000 milliseconds:
First you want to get seconds:
18.000.000 / milliseconds(1000)
Gives you 18.000 seconds.
18.000 / seconds(60) = 300
You now have 300 minutes.
300 / minutes(60) = 5
You now have 5 hours.
If you do: 5 * 60 * 60 * 1000 you should get 18.000.000
I did write wrong on the formula, meant "hours = milliseconds / (minutes*seconds*milliseconds)"
Math example:
Код:
x = a*b*c
x/b = a*c
x/b * 1/c = a
x/(b*c) = a
Basically what I did with the formula.
Re: Converting Float Value to Hours, Days, Months -
Tayab - 12.01.2014
Nice, that was so helpful. Thanks.