473,385 Members | 1,919 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,385 software developers and data experts.

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

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 1340
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.comwrote in message news:BP51h.34135$P7.18677@edtnps90...
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.comwrote 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.comwrote in message news:BP51h.34135$P7.18677@edtnps90...
>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 #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)NoOfClients);

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.comwrote 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.comwrote in message news:BP51h.34135$P7.18677@edtnps90...
>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


Nov 23 '06 #5

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

Similar topics

4
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). ...
4
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...
31
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...
5
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...
0
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
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...
3
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
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"). ...
160
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.