Is_Numeric / Float Detection (Version: 9) - Miva - Snippets
<h2>Background / Abount</h2> <p>I wasn't able to find a way to easily check whether or not a value was a Float or not. <code>isdigit()</code> didn't work, so I tried this logic. <h2>Sample <code>isdigit()</code> with Floats</h2> isdigit(1) = <mvt:eval expr="isdigit(1)" /><br/> isdigit(3.14) = <mvt:eval expr="isdigit(3.14)" /><br/> <mvt:if expr="NOT isdigit(3.14)"> <blockquote>3.14 is not a digit</blockquote> </mvt:if> <h2>Is_Numeric Logic &amp; Cases</h2> <mvt:assign name="l.settings:tests" value="miva_array_deserialize('-2,-1.5,-1,-0.5,0,000.000,0.5,1,1.5,2,3.14159,111111111,,000000-,-,!,@,#,$,%,^,a,b,c,d,-1.b,u.3' )" /> <mvt:foreach iterator="test" array="tests"> <mvt:if expr="len(l.settings:test) AND (l.settings:test EQ 0 OR l.settings:test/l.settings:test EQ 1)"> <mvt:assign name="l.settings:color" value="'green'" /> <mvt:assign name="l.settings:result" value="'PASS'" /> <mvt:else> <mvt:assign name="l.settings:color" value="'red'" /> <mvt:assign name="l.settings:result" value="'FAIL'" /> </mvt:if> <h2 style="color: &mvt:color;"><code>&mvt:result;: "&mvt:test;"</code></h2> <mvt:comment> <mvt:assign name="l.len" value="len(l.settings:test)" /> <mvt:assign name="l.index" value="1" /> <mvt:while expr="l.index LE l.len"> <mvt:assign name="l.settings:char" value="substring( l.settings:test, l.index, 1 )" /> &mvt:char;<br> <mvt:assign name="l.index" value="l.index + 1" /> </mvt:while> </mvt:comment> </mvt:foreach>