Use val() to ensure the variables are numbers. Val automatically converts non-numeric values (like an empty string) to 0.

<cfset VARIABLES.total = val(variables.total) +

val(AmountToPayOnNextCheck

- val(AmountToPayOnNextCheck

Solved

Posted on 2012-08-27

I added a column to one of my coldfusion pages to show the amount of a deduction that occurs in our system when a PO get's paid. I want to do a simple subtraction based on the value that this new column(WrapAmount) holds. I have a total value that I calculate by using the method below:

I've tried simply changing <cfset VARIABLES.total = variables.total + AmountToPayOnNextCheck.TotalAmt />

to

<cfset VARIABLES.total = variables.total + AmountToPayOnNextCheck.TotalAmt - AmountToPayOnNextCheck.WrapAmount />

but the coldfusion debugger tells me "" cannot be converted to a number when I try to view the report. Any assistance is greatly appreciated!

```
<cfoutput query="AmountToPayOnNextCheck" startRow="#StartRow_AmountToPayOnNextCheck#" maxRows="#MaxRows_AmountToPayOnNextCheck#" group="VendCode" groupcasesensitive="true">
<cfset VARIABLES.companyTotal = 0 />
<cfoutput group="PONo">
<cfset VARIABLES.total = 0 />
<cfoutput>
<cfset VARIABLES.total = variables.total + AmountToPayOnNextCheck.TotalAmt />
</cfoutput>
<cfset VARIABLES.companyTotal = VARIABLES.companyTotal + VARIABLES.total />
```

I've tried simply changing <cfset VARIABLES.total = variables.total + AmountToPayOnNextCheck.Tot

to

<cfset VARIABLES.total = variables.total + AmountToPayOnNextCheck.Tot

but the coldfusion debugger tells me "" cannot be converted to a number when I try to view the report. Any assistance is greatly appreciated!

8 Comments

Use val() to ensure the variables are numbers. Val automatically converts non-numeric values (like an empty string) to 0.

<cfset VARIABLES.total = val(variables.total) +

val(AmountToPayOnNextCheck

- val(AmountToPayOnNextCheck

#val(AmountToPayOnNextChec

It returns a 0, not sure if you are willing to chime in on this after the fact, I can post another question if not.

Sounds like you need to calculate the total inside the loop, like you're doing with #total#. Something like this would calc the total for each group. If you need the overall total for the entire query, just initialize the #totalWrapAmount# variable *before* the output loop.

ie

<cfoutput group="PONo">

....

<!--- calculate total for CURRENT group --->

<cfset totalWrapAmount = 0>

<cfoutput>

....

<cfset totalWrapAmount = totalWrapAmount + val(AmountToPayOnNextCheck

</cfoutput>

....

</cfoutput>

<cfset VARIABLES.companyTotal = VARIABLES.companyTotal + VARIABLES.total - val(AmountToPayOnNextCheck

When I try to show the Wrap Total by itself using the code you provided it returns a value of 2.64 which is incorrect for this particular data set. The correct value is reflected in the above total but I can't get just a sum of the WrapAmount to display by itself.

I suspect it's a matter of where you're incrementing the total, but it's impossible to say for sure without seeing a dump of the actual query values. So we can figure out how you're getting 2.64.

The link is:

http://www.experts-exchang

The total "WrapAmount" for this particular query should be 41.13

I posted my code and will post a SS of the query values.

By clicking you are agreeing to Experts Exchange's Terms of Use.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**8** Experts available now in Live!