Skip to main content
johng58900177
Known Participant
June 15, 2020
Question

Math

  • June 15, 2020
  • 2 replies
  • 383 views

having trouble multiplying form variables.  I have not used CFML for years and I am not sure what I am missing. 

 

<cfset variablea - #form.b# * #form.c#>

I have use '' and () in this as well.

    This topic has been closed for replies.

    2 replies

    WolfShade
    Legend
    June 15, 2020
    <cfset variablea - val(form.b * form.c) />

    This assumes that you can guarantee that form.b and form.c are, indeed, parseInt, Int, or float values.

     

    V/r,

     

    ^ _ ^

     

    Community Expert
    June 15, 2020

    OK, there are a couple of things going on. First, your multiplication looks fine, but you've got it as the subtrahend of a subtraction operation. So, that's not going to make sense unless you've got a value in variablea already. (BTW, I had to look up "subtrahend" - it's just a fancy word for "the part after the subtraction sign".) So, you'll probably want to change that to an equality operator.

     

    Second, while what you have will work, most CF developers only use hash marks/pound signs when they want to output a value to the HTML page. So, you could just as easily use

     

    <cfset variablea = form.b * form.c>

     

    Finally, there's nothing here that guarantees that your form variables can be cast as numbers, so you'd probably want to wrap the whole thing in some code to guarantee that. Here's a simple and probably incomplete example.

     

    <cfif isNumeric(form.b) and isNumeric(form.c)>

     ... do your multiplication ...

    <cfelse>

     ... do something else ...

    </cfif>

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC
    johng58900177
    Known Participant
    June 17, 2020

    I do have an = in the actual code.  I flubbed it as I wrote it here.