Hi there,
I just finished making a Seconds -> Minutes converter that lays them out in the format of (m.ss). Eg: (5.00) is 5minutes, (0.05) is 5 seconds.
What I would like is to have it more dynamic so that if it was 15minutes it would say (15.00) and 5 minutes would be (5.00).
Below is the code I wrote, i think its kind of… Weird :D? The two numbers entered into the function are in ‘seconds’.
//Display Minutes / Seconds Duration
function generateTime(nCurrentTime:Number, nCurrentDuration:Number):Void {
var nCurrentTimeConverted:Number = Math.round(nCurrentTime);
var sCurrentTime:String;
var sCurrentDuration:String = (Math.round((nCurrentDuration / 60) * 100) / 100) + "";
//Convert to Minutes
if (nCurrentTimeConverted >= 60) {
nCurrentTimeConverted = Math.round((nCurrentTimeConverted / 60) * 100) / 100;
if (nCurrentTimeConverted.toString().length == 3) {
sCurrentTime = nCurrentTimeConverted + "0";
} else if (nCurrentTimeConverted.toString().length == 1) {
sCurrentTime = nCurrentTimeConverted + ".00";
} else {
sCurrentTime = nCurrentTimeConverted + "";
}
} else {
nCurrentTimeConverted = Math.round(nCurrentTime) / 100;
if (nCurrentTimeConverted.toString().length == 3) {
sCurrentTime = nCurrentTimeConverted + "0";
} else if (nCurrentTimeConverted.toString().length == 1) {
sCurrentTime = nCurrentTimeConverted + ".00";
} else {
sCurrentTime = nCurrentTimeConverted + "";
}
}
dTTime.text = sCurrentTime + " / " + sCurrentDuration;
}
Help would be much appreciated!