Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isNumeric('100e00') returns yes while lsisnumeric('100e00') returns no

Tags:

coldfusion

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?

like image 729
Ander2 Avatar asked Feb 08 '13 12:02

Ander2


1 Answers

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.

like image 184
Adam Cameron Avatar answered Nov 20 '22 00:11

Adam Cameron