473,549 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

3 / 2=1? Strange result in expression...HE LP!

Hi Folks!

I have a strange thing happening; I have a field that Counts the number of
records and another field that shows the number of clients
(Count(RecordID )=3 and NoOfClients=2) When I do a simple expression
"Count(RecordID )/NoOfClients" the expected result should be 1.5. Instead
the result I get is 1. Any ideas?

Thanks!
Rick

Oct 29 '06 #1
4 1348
MC
Try converting one of the values to decimal. For example:
select 3/2 results in 1 BUT
select 3/2. should result in 1.5

Difference is in datatypes...

MC
"Rico" <yo*@me.comwrot e in message news:BP51h.3413 5$P7.18677@edtn ps90...
Hi Folks!

I have a strange thing happening; I have a field that Counts the number of
records and another field that shows the number of clients
(Count(RecordID )=3 and NoOfClients=2) When I do a simple expression
"Count(RecordID )/NoOfClients" the expected result should be 1.5. Instead
the result I get is 1. Any ideas?

Thanks!
Rick

Oct 29 '06 #2
That did the trick. Thanks MC. I thought it had something to do with the
data types, but being a newbie didn't think about "Decimal".

Thanks again!
Rick

"MC" <ma************ **@yahoo.comwro te in message
news:ei******** **@ss408.t-com.hr...
Try converting one of the values to decimal. For example:
select 3/2 results in 1 BUT
select 3/2. should result in 1.5

Difference is in datatypes...

MC
"Rico" <yo*@me.comwrot e in message news:BP51h.3413 5$P7.18677@edtn ps90...
>Hi Folks!

I have a strange thing happening; I have a field that Counts the number
of
records and another field that shows the number of clients
(Count(RecordI D)=3 and NoOfClients=2) When I do a simple expression
"Count(RecordI D)/NoOfClients" the expected result should be 1.5. Instead
the result I get is 1. Any ideas?

Thanks!
Rick


Oct 29 '06 #3
Hi Rick,

you are using integers and in integer division 3/2 is 1.
Use floats or cast your numbers to floats in the calculation:

float result=((float) Count(RecordID) )/((float)NoOfCli ents);

Regards,
Andy

Rico schrieb:
Hi Folks!

I have a strange thing happening; I have a field that Counts the number of
records and another field that shows the number of clients
(Count(RecordID )=3 and NoOfClients=2) When I do a simple expression
"Count(RecordID )/NoOfClients" the expected result should be 1.5. Instead
the result I get is 1. Any ideas?

Thanks!
Rick
Oct 30 '06 #4
Forgot to respond. Thanks! That did the trick!

"MC" <ma************ **@yahoo.comwro te in message
news:ei******** **@ss408.t-com.hr...
Try converting one of the values to decimal. For example:
select 3/2 results in 1 BUT
select 3/2. should result in 1.5

Difference is in datatypes...

MC
"Rico" <yo*@me.comwrot e in message news:BP51h.3413 5$P7.18677@edtn ps90...
>Hi Folks!

I have a strange thing happening; I have a field that Counts the number
of
records and another field that shows the number of clients
(Count(RecordI D)=3 and NoOfClients=2) When I do a simple expression
"Count(RecordI D)/NoOfClients" the expected result should be 1.5. Instead
the result I get is 1. Any ideas?

Thanks!
Rick


Nov 23 '06 #5

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

Similar topics

4
1419
by: hall | last post by:
Hi. I've come across someting strange. I was trying to make a for-loop execute repetadly until the function called inside it does not return true during the entire loop (see program below). The two lines that confuse me are marked as (1) and (2). count=0; bool s(true);
4
4939
by: Rune | last post by:
I have two queries that appear to be exactly the same, but one of them returns null while the other one returns a valid result! Can anyone provide an explanation to why this is so? Below is an nunit test that exposes the problem. I have run the test under both the 1.0 and 1.1 framework with the same result. public void XPathBooks() {...
31
6585
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one variable becomes 364 and the other one becomes 365. Does anyone have any insight to what the problem is? Thanks in advance. Bjørn
5
1053
by: John | last post by:
I have created a program that accesses a flat 2 dimensional array and have developed a routine to sum the four neighbors of a specific row/column position. Here is an example, this will sum all the values of row 1, column 1 (base 0) which is the number 5 int a = {1,2,3,4,5,6,7,8,9}; int* pa = &a; // row 1, column 0 (i.e. number 4)
0
1462
by: Wescotte | last post by:
<?php global $TABLE_GL_DATA; global $connect; $PREPARED_SQL = odbc_prepare($connect, "INSERT INTO $TABLE_GL_DATA VALUES (?,?,?,?,?,?,?)"); function Generate_GL_Data() {
2
1785
TMS
by: TMS | last post by:
The spreadsheet is due today and i needed help with the last two parts of the spreadsheet, so I went to my teacher. My spreedsheet was working BETTER before he made me change it. Now it prints a widget address in one of the cells for no apparant reason (I can't locate why the event is doing that), and it doesn't evaluate. He wants me to...
3
1419
by: Tomasz J | last post by:
Hello Developers, I have a control derived from System.Web.UI.WebControls.WebControl. Control has this property: public string Value { set { _value = value; } get { return _value; }
1
1138
by: dizzy | last post by:
Hello I have noticed a strange behavior (tho for many of you this is to be expected I'm sure :) ) when I have an expression that adds a long value with an unsigned one (like in "10l + 10u"). On 32bit platforms (where unsigned can represent more than long) the result is of unsigned long type while on 64bit platforms the result is of long...
160
5771
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7461
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3509
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1068
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.