- Home /
How to convert 00:40:00.0 to float
How can I convert time ( 00:40:00.0 ) to float. because I want to get the average of the time listed on my leaderboard. ex.
00:20:12.0
00:34:12.0
01:32:12.4
05:12:33.5
12:23:12.1
I want to get the float equivalent of those time and average it.
Answer by GibTreaty · Jan 20, 2013 at 11:05 AM
Check this out. It should be what you're looking for.
String.Split(Char[])
http://msdn.microsoft.com/en-us/library/b873y76a.aspx
string time = "00:20:12.0"
string[] times = String.Split(':','.')
//You may have to parse the string to an int before assigning them
int hours = times[0]; //0
int minutes = times[1]; //20
int seconds = times[2]; //12
int milliseconds = times[3]; //0
Answer by Loius · Jan 19, 2013 at 06:18 PM
Time.time is already a float. Don't you want the opposite conversion?
int totalSeconds = parseInt(time);
int seconds = totalSeconds % 60;
int minutes = (totalSeconds/60) % 60;
int hours = (totalSeconds/3600);
float hundredths = time - totalSeconds;
oh sorry, 00:40:00.0 is string and I want to convert it to float so that I can get the average. btw, how can I get 00:40:50.0 out of "1. 00:40:50.0 - Name" ?
Your answer
Follow this Question
Related Questions
Get time of AudioSource.Clip to System.Date format 1 Answer
Unity Convert more int to one float or String and back? 1 Answer
Add to score every second 3 Answers
Start timer with trigger 1 Answer
Convert type `float' to `bool', Load 1 Answer