It should be on one line. Check the values of cost and lowest to see what they are (display them for testing purposes).
How to output with a control variable inside cfquery name?
Collapse
X
-
Hey Acoder,
Confused on what you mean Check the values of cost and lowest? just output them like #acompare.cost# output it an then change it from that to #lowest# and output it? bit confused on how to check.
so everyone on one line should be something like this?
Code:<cfset cost = #acompare.cost#> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03 and pricediff lt -0.03> #cost# <cfelse> 0 </cfif>
RachComment
-
Hey Acoder,
According to what i am looking at, there both outputting numbers. Its getting the correct value for the lowest company by doing #lowest# and when i do the cost, the cost is matching up correctly and its a number as well by doing #acompare.Cost# . But i know cost is a float and the company price is numeric, i don't know if that makes a difference or not as to why the pricediff wont work.
i know the problem has to be with cost because when i did the following, i got the error Division by zero is not allowed. I know that cost is a float value and lowest is numeric. but not sure how i would convert float to numeric
Code:<cfset cost = #acompare.cost#> <cfset pricediff = ((#lowest# - '#val(cost)#')/'#val(cost)#')> <cfif pricediff gt 0.03> #cost# <cfelseif pricediff lt -0.03> 0 </cfif>
RachComment
-
Hey Acoder,
Actually doing this seemed to help. I am not getting errors anymore an now some of the values are 0 and some are not.But i am not sure if this is the correct solution or not.
Code:<cfset cost = #acompare.cost#> <cfif IsNumeric(cost)> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03> #cost# <cfelseif pricediff lt -0.03> 0 </cfif> </cfif>
but here is what i had before when i was just outputting #acompare.cost#
for line 194 i had 16 49
for line 292 i had 432.8000
an then when i did it with the isnumeric (above) this is what i get
for line 194 i get 0
for line 292 i get 432.8000
i also did a test with the calculator to make sure its right i did for the first one i did
(($9.98 - $16.49)/$16.49) and got the result -0.394 (an the numbers continue)
an then for the second one i did
(($453.97 - $432.80)/$432.80) and i got the result 0.048 (an the numbers continue)
Thank you,
RachComment
-
You need to combine lines 4 and 6:
Code:<cfif pricediff gt 0.03 and pricediff lt -0.03>
What are lines 194 and 292 that you mentioned in the previous post? Are these in the table? Also, does 16.49 have a space, i.e. is it "16 49"? If it is, the IsNumeric() will be false.Comment
-
Hey Acoder,
Definately want to output the price different so instead of using #cost# would i use #pricediff#?. Line 194 and 292 appear in the report.used them because there the first 2 that have something in the price diff column an my bad its 16.49 (typed it wrong).
So would this be correct?
Code:<cfset cost = #acompare.cost#> <cfif IsNumeric(cost)> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03 and pricediff lt -0.03> #pricediff# <cfelse> N/A </cfif> </cfif>
RachComment
-
Hey Acoder,
So would this be correct? not sure if i got the cost neq in the right spot or not. not sure if it should be before or after isnumeric
Code:<cfset cost = #acompare.cost#> <cfif IsNumeric(cost)> <cfif cost neq 0> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03 and pricediff lt -0.03> #pricediff# <cfelse> N/A </cfif> </cfif> </cfif>
RachComment
-
Hey Acoder,
I tried it the way i had it and tried it your way an now all the values for the price diff say n/a. I think its cause when you do the price diff at the beginning of all of them they had 0.0 in front? Any suggestions?
Code:<cfset cost = #acompare.cost#> <cfif IsNumeric(cost) and cost neq 0> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03 and pricediff lt -0.03> #pricediff# <cfelse> N/A </cfif> </cfif>
RachComment
-
Hey Acoder,
I know the neq 0 part is failing,because the isnumeric was working before. But cost is a float field in the table, not sure if its a string or not. Just know its float.
But i took out the cost neq 0 to make sure it was causing it and turns out its me using #pricediff# to output it is causing the problem. Its saying n/a for all of them based on i changed #cost# to pricediff#.Any suggestions?
Code:<cfset cost = #acompare.cost#> <cfif IsNumeric(cost) and cost neq 0.0> <cfset pricediff = ((#lowest# - cost)/cost)> <cfif pricediff gt 0.03 and pricediff lt -0.03> #pricediff# <cfelse> N/A </cfif> </cfif>
RachComment
Comment