我工作的方法計算轉換率,問題是我分配訪客與訂單,並得到一個結果(整數如84),但當我分開反過來我得到0.0。計算詮釋爲十進制失敗
如果我devide訂單用計算器訪問的結果看起來是這樣的:
0,0118694362017804
但是我不得不結果顯示爲百分比,所以我應該縮短結果00,00不知何故。 Annyways它的奇怪它dosn't工作兩種方式,我想知道什麼問題?
控制器的方法:
public List<GC_ConversionRateModel> GetConversionReport(GAStatisticsListModel model)
{
DateTime? startDateValue = (model.StartDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
DateTime? endDateValue = (model.EndDate == null) ? null
: (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
List<GAVisitorsModel> VisitorsList = GetGAStatisticsReport(model);
List<GC_OrdersModel> OrdersList = GetOrderReport(model);
List<GC_ConversionRateModel> TotalConversions = new List<GC_ConversionRateModel>();
OrdersList.ForEach(o =>
{
TotalConversions.Add((from v in VisitorsList
where v.Date == o.Date
select new GC_ConversionRateModel(o.Date, v.Visitors/o.TotalOrders)).FirstOrDefault());
});
return TotalConversions;
}
這些是對象類:
GAVisitorsModel:
public class GAVisitorsModel : IGAVisitorsModel
{
public string Date { get; set; }
public int Visitors { get; set; }
public GAVisitorsModel(string _date, string _visitors)
{
Date = _date;
Visitors = _visitors;
}
}
GCOrdersModel:
public class GC_OrdersModel
{
public string Date { get; set; }
public int TotalOrders { get; set; }
public int TotalProducts {get; set;}
public GC_OrdersModel(string _date, int _totalOrders, int _totalProducts)
{
Date = _date;
TotalOrders = _totalOrders;
TotalProducts = _totalProducts;
}
}
GC_ConversionRateModel:
public class GC_ConversionRateModel
{
public string Date { get; set; }
public decimal ConversionRate { get; set; }
public GC_ConversionRateModel(string _date, decimal _conversionRate)
{
Date = _date;
ConversionRate = _conversionRate;
}
}
THX
同樣的問題一遍又一遍...... –
可能的重複的[C#:除以100](http://stackoverflow.com/questions/5242436/c-divide-an-int-by-100)或[ C#:int劃分不帶小數](http://stackoverflow.com/questions/11568986/c-sharp-int-division-without-decimals)或[C#:Division返回零](http:// stackoverflow。com/questions/9288904/division-returns-zero) –