# How do I convert decimal minutes like 90 -\> 1:30?

**URL:** <https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457>\
**Category:** Uncategorized\
**Created:** [December 12, 2002, 4:09am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457 "2002-12-12T04:09:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_X](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Mr\_X](https://forum.kirupa.com/u/Mr_X)\
**Post date:** [December 12, 2002, 4:09am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/1 "2002-12-12T04:09:26Z")

</div>

I need to make a dynamic text field display Sound.duration like 1:30sec instead of 90sec (for exemple…).  
I was not a maths major… I studied that long ago… I think… But I have no clue…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2002, 9:36am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/2 "2002-12-12T09:36:32Z")

</div>

seconds = 90;  
minutes = (Math.floor(seconds/60)) + “:” + (seconds%60);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2002, 4:54pm UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/3 "2002-12-12T16:54:23Z")

</div>

Sbeener, will you marry me? 😉  
I kinda remember that “floor” thing from ASDG but I couldn’t remember its name…

ok, so I got that from what you gave me:

```auto

	var totTimeMin, totTimeSec, elapsTimeMin, elapsTimeSec;
	totTimeMin = Math.floor(Math.round(_root.mp3.duration/1000)/60);
	totTimeSec = Math.round(_root.mp3.duration/1000)%60;
	elapsTimeMin = Math.floor(Math.round(_root.mp3.position/1000)/60);
	elapsTimeSec = Math.round(_root.mp3.position/1000)%60;
	if (stopped != true) {
		totalTime = totTimeMin+":"+totTimeSec;
		elapsTime = elapsTimeMin+":"+elapsTimeSec;
		remaiTime = (totTimeMin-elapsTimeMin)+":"+(totTimeSec-elapsTimeSec);
	}

```

Now, I know I’m totally getting advantage of your generosity here but… Is there a way to get some leading zeros there like: “00:04” instead of “0:4”… Again, only if you have the free time… THX! 🙂  
ps: I making a simple music player interface…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2002, 9:20pm UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/4 "2002-12-12T21:20:01Z")

</div>

```auto

// define this function somewhere...
function millisecondsToMinutes(msec){
   var m = Math.floor(msec/60000);
   var s = Math.floor(msec%60000 / 1000);
   if(s<10) s = "0" + s;
   return m + ":" + s;
}

// then this code to find the times...
if(!stopped){
   var t = _root.mp3.duration;
   var p = _root.mp3.position;
   totalTime = millisecondsToMinutes(t);
   elapsTime = millisecondsToMinutes(p);
   remaiTime = millisecondsToMinutes(t-p);
}

```

so i the code to parse the milliseconds to a conventional time format into a function. this made the code to build the display a little cleaner.

adding the zero is handled with a simple if statement, you could do the same for the minutes if you like.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 14, 2002, 12:53am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/5 "2002-12-14T00:53:37Z")

</div>

ok, you’re the man…

I’m definitly trying to go through your code slowly to learn from it… I know my code is so messy… the if (!stopped) looks so much sexyer than if (stopped != true)… How did you learn to code? I want to get there but my maths sucks… like the modulo thing… I remember reading about it but I could never have come up with little equation thing to get the time… Ho well I got Rob Penners book (it’s pretty amazing so far, very insightfull guy…) and I’m awaiting the MX version of Mook’s ASDG… Anything else you’d recommend?

as far as the code, I thought the millisecond looked cool so I modified your code slightly like that:

```auto

function millisecondsToMinutes(msec) {
	var m = Math.floor(msec/60000);
	var s = Math.floor(msec%60000/1000);
	var ms = Math.floor(msec%100);
	if (s<10) {
		s = "0"+s;
	}
	if (m<10) {
		m = "0"+m;
	}
	if (ms<10) {
		ms = "0"+ms;
	}
	return m+":"+s+":"+ms;
}

```

and it seems to work fine… I tried to understand the modulo thing from your exemple but I’m not %100 clear about how it works… I should never have studied music in college!! ☹

Anyway, the site is almost done and I’ll let you know about it if you wanna see what it was all about 😉 THX!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 14, 2002, 1:03am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/6 "2002-12-14T01:03:09Z")

</div>

robert penner’s pretty brilliant. apparently brendan hall’s book on oop actionscript is good too. it’s not fundamentals, it’s higher level stuff, but it never hurts to get off on the right foot.

modulo means take the remainder when i divide the left side by the right side. so:

14%3 = 2

because

14 / 3 = 4 with a remainder of 2

i learned my coding through the internet and experimentation (and a few things from [kirupa.com](http://kirupa.com) too!). there’s a great tutorial on oop online courtesy of robin debruiel. that catapulted my abilities significantly and some day i hope to repay him for that.

i studied music in college too, percussion major. nice cd collection incidentally.

cheers.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 14, 2002, 1:18am UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/7 "2002-12-14T01:18:29Z")

</div>

is that what you’re talking about?  
[http://www.debreuil.com/docs/ch01\_Intro.htm](http://www.debreuil.com/docs/ch01_Intro.htm)  
a far as cd collection, if you have access to a Mac, you have life account on my carracho server! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 14, 2002, 12:20pm UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/8 "2002-12-14T12:20:15Z")

</div>

> \*Originally posted by sbeener \*  
> \*\*  
> i learned my coding through the internet and experimentation (and a few things from [kirupa.com](http://kirupa.com) too!). there’s a great tutorial on oop online courtesy of robin debruiel. that catapulted my abilities significantly and some day i hope to repay him for that.

i studied music in college too, percussion major. nice cd collection incidentally.

cheers. \*\*

I learned from this website as well. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 15, 2002, 5:26pm UTC](https://forum.kirupa.com/t/how-do-i-convert-decimal-minutes-like-90-1-30/9457/9 "2002-12-15T17:26:40Z")

</div>

that’s the one - debreuil. pardon my previous spelling. i received some top notch advice from the message board there too, highly recommended.

malheursement, i don’t use a mac. there’s a few kicking around the office though, maybe i’ll give it a try on one of those.
