帮我。
我正在用 C# 开发一个应用程序。我在尝试:
DateTime dtm1 = new DateTime(2012, 11, 15, 11, 3, 0);
DateTime dtm2 = new DateTime(2012, 11, 15, 11, 3, 20);
TimeSpan timespan3 = dtm2 - dtm1;
decimal _Hour = Convert.ToDecimal(timespan3.TotalHours);
什么时候做这样的输出如下:
_Hour = 0.00555555555555556M
而这不完全是,当使用是一种双倍输出时:
double _Hour = timespan3.TotalHours;
output: 0.0055555555555555549
一个例子:
public decimal tinhDienTichHinhThang(decimal D1, decimal D2, decimal H)
{
//tính tổng 2 đáy
decimal tong2Day = D1 + D2;
//cộng vào nhân chiều cao :))
tong2Day = tong2Day * H;
//return diện tích
return tong2Day / 2;
}
DateTime dtm1 = new DateTime(2012, 11, 15, 11, 3, 0);
DateTime dtm2 = new DateTime(2012, 11, 15, 11, 3, 20);
TimeSpan timespan3 = dtm2 - dtm1;
///progress
///cal1: _Hour
///cal2: decimal D1 = 0.25
///cal3: decimal D2 = 5
///cal4: decimal D3 = 0.9
decimal test1 = (decimal test1 = Math.Round((D1 + tinhDienTichHinhThang(D2, 0, Convert.ToDecimal(timespan3.TotalHours))) * D3, 3, MidpointRounding.AwayFromZero);
输出:test1 = 0.237
如果手动计算:
test1 = Math.Round((0.25 + ((5+0)*timespan3.TotalHours/2))*0.9, 3, MidpointRounding.AwayFromZero);
输出:test1 = 0.238(确切地说:0.2375)
注意:计算win XP 则准确:0.2375 但计算win 7 则不准确。
请解释一下我为什么和解决这个问题的问题的方式?