Im working on a method calculating conversion rate, problem is i devide Visitors with orders and get a result (whole numbers like 84) but when i divide the other way around i get 0.0.
If i devide orders with visits with a calculator the result looks something like this:
0,0118694362017804
However i have to display the result as percent so i should shorten the result to 00,00 somehow. Annyways its strange it dosn't work both ways and im wondering what's the problem?
Controller Method:
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;
}
These are the object classes:
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