我要做的就是找到员工的加班时间。考勤表以CSV文件格式提供,我已经将数据保存到表格中了。数据字段小时为12:10:00.0000000,每天的工作时间为11:00:00.0000000。我已经使用Timespan计算了两次之间的差异。
DateTime date, hours, working_hours ;
TimeSpan ot_hours = TimeSpan.Zero;
TimeSpan tot_hours = TimeSpan.Zero;
if (hours > working_hours)
{
ot_hours = (hours - working_hours);
}
此代码已设置为循环。完成循环后,我需要将总的加班时间分配到另一个变量中。这样写
tot_hours += tot_hours + ot_hours;
接下来,我需要找到该员工的加班费。我试图将此tot_hours(TimeSpan)转换为Decimal。但这没有用。
tothrsvalue = Convert.ToDecimal(tot_hours);
totalvalue = rate * tothrsvalue;
这里的任何人..请看看并帮助我..在此先感谢。
总计算部分如下:
decimal basics = Convert.ToDecimal(dtamt.Rows[0]["Amount"].ToString());
decimal rate = 0;
rate = ((basics / 30) / 8);
txtrate.Text = rate.ToString("0.000");
tothrsvalue = Convert.ToDecimal(total);
totalvalue = rate * tothrsvalue;
txtamount.Text = totalvalue.ToString("0.000");
amt = Convert.ToDecimal(txtamount.Text);
解析TimeSpan
到decimal
不太多意义,因为时间是不是一个数值在所有。
但是您可以使用返回的TotalHours
属性double
。
var total = tot_hours.TotalHours;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句