Skip to main content
Known Participant
March 28, 2011
Answered

Calculation not outputting overall value

  • March 28, 2011
  • 2 replies
  • 632 views

Hi, I have variables that represent numerical values and when i try outputting a product or quotient of these values, all i recieve is the values themselves. I may be a little vague but an example should help clear this up.

For example:

A=4

B=2

C=3

D=A*B/C

<cfoutput>#D#</cfoutput>

and I will get 4*2/3

not 2.6667

How can i get it to display 2.6667

    This topic has been closed for replies.
    Correct answer ilssac

    OK usually ColdFusion is typeless and it should not care, but you are REALLY putting that typeless, forgiving nature to the test.

    Try some simplier code.

    <cfset A = 4>

    <cfset B = 2>

    <cfset C = 3>

    <cfset D = A * B / C>

    <cfoutput>#D#</cfoutput>

    You where setting three strings, which ColdFusion would normally automatically convert to numbers, if you made it do math.  But then instead of doing math, you create another string by concatenating the original three variables and some mathematical operators.

    2 replies

    Known Participant
    March 28, 2011

    I am using cfset. Sorry for not including it in the original post.

    For example:

    <html>
    <head>
        <title>Untitled</title>
    </head>

    <body>
    <cfset A="4">
    <cfset B="2">
    <cfset C="3">

    <cfset D="#A#*#B#/#C#">

    <cfoutput>#D#</cfoutput>


    </body>
    </html>

    I would get 4*2/3 and not 2.666

    ilssac
    ilssacCorrect answer
    Inspiring
    March 28, 2011

    OK usually ColdFusion is typeless and it should not care, but you are REALLY putting that typeless, forgiving nature to the test.

    Try some simplier code.

    <cfset A = 4>

    <cfset B = 2>

    <cfset C = 3>

    <cfset D = A * B / C>

    <cfoutput>#D#</cfoutput>

    You where setting three strings, which ColdFusion would normally automatically convert to numbers, if you made it do math.  But then instead of doing math, you create another string by concatenating the original three variables and some mathematical operators.

    Known Participant
    March 28, 2011

    Thanks a lot. Appreciate it.

    ilssac
    Inspiring
    March 28, 2011

    What does your code actually look like?

    I presume you are using <cfset...> and|or <cfscript...> tags somewhere along there?

    Because if you are just typing strings into your CFML like you did your post here, then you are getting the expected results, the output of those strings.