【发布时间】:2016-05-09 17:06:22
【问题描述】:
我所要做的就是找到员工的加班时间。考勤表采用 CSV 文件格式,我已经将数据保存到表格中。数据 Field hours 为 12:10:00.0000000,The Working Hour per day 为 11:00:00.0000000。我已经使用时间跨度计算了这两次之间的差异。
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 ) 转换为十进制。但它没有用。
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);
【问题讨论】:
-
我预计
tot_hours += tot_hours + ot_hours;是错误的,因为这基本上意味着加倍总数,然后加上加班。如果总数为0,那么您不会注意到这是一个问题,但在其他情况下会导致不正确的结果。你应该只使用tot_hours += ot_hours;或tot_hours = tot_hours + ot_hours; -
是的.. 谢谢@musefan .. 那是我的错误。我已经更正了
标签: c# asp.net datetime decimal type-conversion