0

I am calculating the total length of my video and watch video length in seconds.

When I click on the button in my ASP.NET MVC page called in which I passed the data

Total Length: 131
Total Watch: 233

Here total length means my video "total length" is 233 seconds and "Total watch" means I have watched 131 seconds video.

233 Seconds means: 3.53 (Min: Sec)
131 Seconds means: 2.11 (Min: Sec)

Now in my database, I have to convert the SECONDS into minutes and then insert the data.

So I have used this code:

ViewDuration = Math.Round((myModel.myWatchCount / 60), 2),
VideoLength = Math.Round((myModel.VideoLength / 60), 2),

Pass the value ViewDuration and VideoLength in the database table.

It shows me

Video Length : - 3.88
Video Duration: - 2.18

What's wrong with the above code? Please suggest?

Edit Code Here is my MVC Controller. How I assign the value to my Class Field.

StudentInfo uvi = new StudentInfo()
{
  ViewDuration = Math.Round((myModel.myWatchCount / 60), 2),
  VideoLength = Math.Round((myModel.VideoLength / 60), 2)
}               
slasky
  • 2,726
  • 4
  • 27
  • 36

1 Answers1

1

You should get the remainder after dividing the time in seconds by 60 and append it to the minute value like this if you want the seconds count be expressed in a fraction of 60 instead of 100.

var time = $"{timeInSeconds / 60}:{timeInSeconds % 60}";

For example

var time = $"{233/60}:{233 % 60}";
Qudus
  • 1,440
  • 2
  • 13
  • 22