Simple Division

  • Thread starter Thread starter Colin Basterfield
  • Start date Start date
C

Colin Basterfield

Hi there,

I have come back to C# from a Delphi project and got myself stuck with a
simple division.

I have the following expression

perDayCount = (_daysInMonth / budgetTotal.BudgetCount);

where

perDayCount is float
_daysInMonth is int
budgetTotal.BudgetCount is short

now the values for one of the rows in my set are

_daysInMonth = 30
budgetTotal.BudgetCount = 300

Now I want 0.1 out which is the answer of course but perDayCount comes out
at 0.0 each time, which causes my next calc to fail.

Can anyone put me out of my misery please?

Many thanks in advance
Colin
 
Hi there,

I have come back to C# from a Delphi project and got myself
stuck with a simple division.

I have the following expression

perDayCount = (_daysInMonth / budgetTotal.BudgetCount);

where

perDayCount is float
_daysInMonth is int
budgetTotal.BudgetCount is short

now the values for one of the rows in my set are

_daysInMonth = 30
budgetTotal.BudgetCount = 300

Now I want 0.1 out which is the answer of course but perDayCount
comes out at 0.0 each time, which causes my next calc to fail.

Can anyone put me out of my misery please?

Colin,

Cast the integers to floats to make the calculation work:

perDayCount =
((float) _daysInMonth / (float) budgetTotal.BudgetCount);
 
Hi Chris,

That worked of course, many thanks, uh duh I also realised that I had the
formula round the wrong way it should have been:

perDayCount = (budgetTotal.BudgetCount / _daysInMonth);

It is working out the budget for less than a whole month, which the budgets
are based on, so I was trying to work out the per day count and then I
multiply that by the number of days in the month selected, but the original
way round wasn't right anyway, but now it is and it works so thanks again

Colin
 
Back
Top