Monday, March 19, 2012

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

Quote:

Originally Posted by

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
>
>
>

|||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" <marko_culoNOSPAM@.yahoo.comwrote in message
news:ei2qf1$a13$1@.ss408.t-com.hr...

Quote:

Originally Posted by

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

Quote:

Originally Posted by

>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
>>
>>
>>


>
>

|||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:

Quote:

Originally Posted by

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

|||Forgot to respond. Thanks! That did the trick!

"MC" <marko_culoNOSPAM@.yahoo.comwrote in message
news:ei2qf1$a13$1@.ss408.t-com.hr...

Quote:

Originally Posted by

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

Quote:

Originally Posted by

>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
>>
>>
>>


>
>

No comments:

Post a Comment