the following code is producing the wrong percent. THis is simple spending/bud to give the percent spent of the budget and the percent availalbe. But when i code this change the app blows up.
as you can see here but when i flip budge.value and i.amount, it blows up.
decimal budgetSum = StateManager
.Instance.GetCategoryBudget(c);
i.BudgetDiffExpense = budgetSum - i.Amount;
// (from t in transactions
// select t.Budget).FirstOrDefault();
i.Budget =
Math
.Abs(i.Amount)-i.BudgetDiffExpense.Value;
//if (i.BudgetDiffExpense.Value < 0)
// i.Variance = 100 - i.BudgetDiffExpense.Value / i.Amount * 100 * -1;
//else
if
(i.Amount != 0)
{
i.Variance = (i.Budget.Value / i.Amount - 1);
}
else
{
i.Variance =
null
;
}
if
(i.Budget != 0)
i.PercDiff = i.Amount / i.Budget ;
Logger.Debug("SpendingListCtrl.cs: CreateCategoryChartLegendItem: budget: {0}, Amount: {1}"
,
i.Budget, i.Amount);
return
i;
}
as you can see here but when i flip budge.value and i.amount, it blows up.
decimal budgetSum = StateManager
.Instance.GetCategoryBudget(c);
i.BudgetDiffExpense = budgetSum - i.Amount;
// (from t in transactions
// select t.Budget).FirstOrDefault();
i.Budget =
Math
.Abs(i.Amount)-i.BudgetDiffExpense.Value;
//if (i.BudgetDiffExpense.Value < 0)
// i.Variance = 100 - i.BudgetDiffExpense.Value / i.Amount * 100 * -1;
//else
if
(i.Amount != 0)
{
i.Variance = (i.Budget.Value / i.Amount - 1);
}
else
{
i.Variance =
null
;
}
if
(i.Budget != 0)
i.PercDiff = i.Amount / i.Budget ;
Logger.Debug("SpendingListCtrl.cs: CreateCategoryChartLegendItem: budget: {0}, Amount: {1}"
,
i.Budget, i.Amount);
return
i;
}