c# - Varchar[HH:MM] SUM in DataGridView -


I have a cell Datagridview in which the varchar values ​​are with the HH: MM format, when I make a sum of these values I need to use the function

  Private Zero CalcTime {string span = dataGridView1.Columns ["Horas"]. ToString (); Double seconds = 0; Secs = datagrid view 1. RAVE .STAT & LETTEDATED DATA CERTIFICATE & gt; (). Asymmetrical () .Sum (x => TimSpace purse ((x.Cells ["Horas"]. Value.ToString ())). TotalSeconds; String somat = ""; Double Segundosec = Second; Somat = string.Format ("{0:00}: {1:00}", Segundosac / 3600, (Segundosec / 60)% 60, Segundosecz% 60); }  

If the values ​​are like 01:00 or 03:00 then this is fine, but if I had values ​​like 01:30 yoga does not work. As shown below: Enter image details here

How do I work it right Can i Regards

The problem is that the sum of seconds will be 20400 and when you divide by 3600, you get '5.666666 and Because your variable is a double and you're using the format {0:00} , the value will be completed to you either the int amount Need to insert or use Math.Floor .

  int seconds = (int) dataGridView1.Rows .Cast & lt; Data GridViewRo & gt; (). ANN Merebel () SUM (x = & gt; timespain.pars ((x.Cells ["Horace"]. Value.ToString ())). Total seconds;  

OR

  somat = string.Format ("{0:00}: {1:00}", Math.flur (Segundosec / 3600) , (Segundosec / 60)% 60);  

In addition you do not need the final parameter in your string.format .

Change one more option to TimeSpain with TimSpain. Foamsecond .

  Double seconds = Datagrid view 1. Rao. Stats & lt; Data GridView & gt; (). ANNMERABLE () .SUM (x = & gt; timespace.pars ((x.Cells ["horse"]. Value.ToString ())). Total seconds; Timespace totem = timespan Foamsecond (seconds); String somat = totalTime.ToString (@ "hh \: mm");  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -