I've just seen that isNumeric('100e00') returns yes while lsisnumeric('100e00') returns no.
I've checked another hex digits (a,b,c,d) but it returns no with them.
Does anyone know why is it considered 100e00 as a numeric value?
100e00 is scientific notation, ie: 100 * 10^0, or: 100.
<cfset string = "100e00">
<cfset numeric = val(string)>
<cfoutput>
values:<br />
string: #string#<br />
numeric: #numeric#<br />
<hr />
isNumeric()<br />
string: #isNumeric(string)#<br />
numeric: #isNumeric(numeric)#<br />
<hr />
lsIsNumeric()<br />
string: #lsIsNumeric(string)#<br />
numeric: #lsIsNumeric(numeric)#<br />
</cfoutput>
This outputs:
values:
string: 100e00
numeric: 100
isNumeric()
string: YES
numeric: YES
lsIsNumeric()
string: NO
numeric: YES
The functionality of isNumeric() and lsIsNumeric() differ slightly beyond the locale-awareness of the latter.
isNumeric() states this: "Determines whether a string can be converted to a numeric value" (my emphasis)
lsIsNumeric() states: "Determines whether a string is a valid representation of a number"
Do you see the subtle difference? the former will try to force the value to be a numeric, whereas the latter just does what it's told: tells you if it's a numeric or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With