Determining if a string is not null/blank and is a number and not 0?

Reno picture Reno · Oct 13, 2011 · Viewed 21.3k times · Source

I normally don't work in ColdFusion but there's a FTP process at work I have to create a report for with the only option right now being a ColdFusion 8 server. This FTP feed has a few issues (trash too).

So, I make the query and then I need to convert some of the string values during the output to do some math. Before that:

How do I tell if a field in the output loop: is not blank or null, is string that can be converted into a valid number, and is not 0?

Is there a simple way of doing this w/o a lot of if statements?

Thanks!

Answer

Peter Boughton picture Peter Boughton · Oct 13, 2011

So you want to make sure that the variable is numeric but not zero?

Then you want this:

<cfif IsNumeric(MyVar) AND MyVar NEQ 0 >