• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Math

New Here ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

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.

Views

292

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 17, 2020 Jun 17, 2020

Copy link to clipboard

Copied

LATEST

What if I want to us a certain number of places in an order number?  it is comprised of the data and 4 more places which is the cordcount of the date entered plus 1.

 

I have this working but not with the extra 0's in front of the second part of the order number.  So today would start with 061720202 which is the second order of the day.  I want 06172020002

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 15, 2020 Jun 15, 2020

Copy link to clipboard

Copied

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

 

^ _ ^

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation