Код: Выделить всё
var currentDate = startdate;
while (currentDate enddate) monthEnd = enddate;
var daysInCurrentMonth = Convert.ToDecimal(Math.Truncate((monthEnd - monthStart).TotalDays + 1));
// Proportion of the amount for this month
var monthlyAmount = decimal.Parse((daysInCurrentMonth / totalDays).ToString()) * Amount;
// Apply discount if applicable
monthlyAmount = Math.Round((Discount != null ? monthlyAmount * (1 - (Decimal.Parse(Discount.ToString()) / 100)) : monthlyAmount),3);
// Add to the result list
monthlyAmounts.Add(
(ContractType,
monthStart,
monthEnd,
monthStart.Month.ToString(),
monthStart.Year,
monthlyAmount,
NetworkID,
NetworkTitle,
MediumTitle,
(MediumID != null ? MediumID.ToString() : null),
BookingCalendarID,
BookingCalendarIDSalesRepIDMap
.SingleOrDefault(a => a.Key == BookingCalendarID).Value, daysInCurrentMonth, totalDays, monthlyAmount)
);
// Move to the next month
currentDate = monthEnd.AddDays(1);
}
Мой вопрос касается этих двух строк кода: -
Код: Выделить всё
var monthlyAmount = decimal.Parse((daysInCurrentMonth / totalDays).ToString()) * Amount;
// Apply discount if applicable
monthlyAmount = Math.Round((Discount != null ? monthlyAmount * (1 - (Decimal.Parse(Discount.ToString()) / 100)) : monthlyAmount),3);
monthlyAmount = 4/14 * 1,000 = 285,7142857142857
monthlyAmount = Math.Round(285.7142857142857 * 0.85,3) = 242,857 JOD
Кроме того, когда я сделаю расчет за октябрь, я получу 607,142.. Но когда я суммирую 242,857 + 607,142 = 849,999 .. потеря 0,001 иорданского динара.. и как мне это исправить?
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/790 ... act-weight