0

I currently need to find the percentage of a song (for my program), I have tried doing it the normal way of (current position)/(total length of song), however since seconds go up to 60 and not 100 this does not work. How would I do this with seconds? Both the current position and length of song are in seconds.

To be more clear, how would I work out the percentage of the song, knowing that I am currently 122.277seconds the way through a song that is total of 177320seconds.

Thanks

2 Answers2

1

You can do this in the usual way, as long as both current position and total length of the song are in the same units (e.g. seconds or minutes or hours, etc). In your example it would be $$ \frac{122.277}{177320} \approx 0.0689 \% $$

(You must have a really long song, $177320$ seconds is about 50 hours, you sure you got the right units?)

gt6989b
  • 54,422
  • My program must be giving me the wrong information then, hmm. That may explain why I am getting the wrong results. The song is only ~3mins – theUser123 Oct 28 '15 at 18:17
  • @guest123 could you be getting the result in milliseconds, i.e. song is $$177320 \textrm{msec} = 177.320 \textrm{sec} = 2 \textrm{min} 57.32 \textrm{sec}?$$ The answer above then is rescaled by 1000 to become $$\frac{122.277}{177.32} = 68.9%$$ – gt6989b Oct 28 '15 at 18:19
  • Think it is, thanks for that. Some reason it looks as if I am getting the current position in seconds and the total length in milliseconds. Strange, the API only documented that it was in seconds, what ever your suggestion works with the songs I tried. Thanks for that tip! Glad to know it wasn't my maths and that it was a program error instead. – theUser123 Oct 28 '15 at 18:23
  • @guest123 familiar problem. Now you have to watch what happens when they upgrade the library you are using fixing the bug -- your estimates would be off by a factor of 1000 :-) – gt6989b Oct 28 '15 at 18:25
  • Yep, the fun of documentations being wrong. Also this is using the library inside the Spotify application which updates quite frequently. What fun this will be when I find out something goes wrong! – theUser123 Oct 28 '15 at 18:27
1

Like gt6989b said, if you're just working in seconds there is no problem and you can just use the convensional way. This is the easy way.

But let's say you are currently at $1'20"$ from a $3'35"$ song you can either calculate it back to seconds or calculate it in minutes, but recalibrate the second part to an accaptable comma value.

$$20 seconds = (20 \times \frac{5}{3})minutes = 0.33 minutes$$

so $1'20" = 1.33$ minutes

$$35 seconds = (35 \times \frac{5}{3})minutes = 0.58 minutes$$

so $3'35" = 3.58$ minutes

The percentage calculated with minutes $=\frac{1.33}{3.58}=0.371$

Ruts
  • 651