473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Simple Division

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

--
Colin Basterfield
Off the Roof Solutions
Nov 16 '05 #1
2 6480
"Colin Basterfield" <co**************@hotmail.com> wrote in
news:eX**************@TK2MSFTNGP09.phx.gbl:
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);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
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

--
Colin Basterfield
Off the Roof Solutions
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Colin Basterfield" <co**************@hotmail.com> wrote in
news:eX**************@TK2MSFTNGP09.phx.gbl:
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);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Go1369 | last post by:
I am trying to divide one number by another and I can't get it to return the right value.... in general I want to see how many fruits I have, then get the number of apples and divide the apples...
5
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume...
13
by: tindog | last post by:
I am brand new to this programming especially C#. I am confused (at the moment). I have bought two books to get started to learn C# language and Visual C#.net 2003 in 24 hours. Which is the best to...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
1
Death Slaught
by: Death Slaught | last post by:
I will be showing you how to make a very simple but effective three column layout. First we will begin with the HTML, or structure, of our three column layout. <!DOCTYPE html PUBLIC...
2
by: richard | last post by:
In using the simple code below, how do I tell it NOT to hide a division when the link is clicked on if that division is already visible? would it be as simple as using a 2nd function and setting...
0
by: gerry | last post by:
for anyone interested I did find a solution : .outer { float:left; border:solid 1px black; overflow:hidden: } .full {
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.