這裏是我的代碼與非零分母除分子總是給人在C#零
DataTable dt=STP_GetRenewalResultsReportData(Convert.ToDateTime("06-07-2015"),Convert.ToDateTime("06-07-2016")).Tables[0];
(
from r in
(
from d in dt.AsEnumerable()
group d by d.Field<string>("CityID") into grpCity
select new{
CityID = grpCity.Key,
City = (from g in grpCity where g.Field<string>("CityID") == grpCity.Key select g.Field<string>("City")).First().Trim(),
PotentialRenewalCount = (from g in grpCity where g.Field<string>("CityID") == grpCity.Key select g.Field<int>("PotentialRenewalCount")).Sum(),
// PotentialRenewalCount = 205,
PotentialRenewalSQRT = (from g in grpCity where g.Field<string>("CityID") == grpCity.Key select g.Field<double>("PotentialRenewalSQFT")).Sum(),
RENEWALCOUNT = (from g in grpCity where g.Field<string>("CityID") == grpCity.Key select g.Field<int>("RENEWALCOUNT")).Sum(),
// RENEWALCOUNT = 23,
RENEWALSQRT = (from g in grpCity where g.Field<string>("CityID") == grpCity.Key select g.Field<double>("RENEWALSQRT")).Sum(),
}
)
select new{
CityID=r.CityID,
City=r.City,
PotentialRenewalCount=r.PotentialRenewalCount,
PotentialRenewalSQRT=r.PotentialRenewalSQRT,
RENEWALCOUNT=r.RENEWALCOUNT,
RENEWALSQRT=r.RENEWALSQRT,
LeaseNoPercentage=Convert.ToDouble(12/30)
}
).Dump();
現在當你在看這條線在底部
LeaseNoPercentage = Convert.ToDouble(12/30 )
我正在將一個非常小的數30和作爲結果我得到0時確切的結果是0.4
所以我的問題是我怎麼能得到0.4在這個LINQ而不是0
感謝你的幫助
爲什麼不使用'12D/30d'(我不知道這是否正常工作) –
即使'轉換.ToDouble((12/30));'可能會產生不同的結果。但是你真的每次都在做12/30嗎?如果這就是你所需要的,爲什麼不能只有0.4的恆定值。 – pay
你真的想做什麼?如果你所要做的只是分割2個int文字並得到一個double,那麼你可能只需要'LeaseNoPercentage = 0.4' –