Why does IsNumeric("1.23D45") return True?
Asked Answered
C

1

5

For the longest time, I thought IsNumeric("1.23E45") returned True because the "E" stands for scientific notation, making 1.23E45 be 1.23x1045.

Recently I noticed IsNumeric("1.23D34") also returned True, and I'm stumped about why.

Both D and E produce the same result:

?val("1.23d45")
 1.23E+45 

?val("1.23e45")
 1.23E+45 

How come?

Conversant answered 20/4, 2016 at 4:35 Comment(0)
C
11

This came up in chat


According to Wikipedia...

FORTRAN also uses "D" to signify double precision numbers.

"UH Mānoa Mathematics » Fortran lesson 3: Format, Write, etc". Math.hawaii.edu. 2012-02-12. Retrieved 2012-03-06.

VBA still has many traces of its BASIC ancestor (line numbers, GoSub..Return, Rem, etc.) - it just so happens that BASIC finds its roots in... FORTRAN.

So that "D" for scientific notation is apparently nothing more than a blast from the past.

Bottom line, avoid confusing whoever is maintaining your code, and stick to "E" (or "e"). But know that "D" (or "d") is also supported, if you ever need to port some FORTRAN code to ...VBA.

Conversant answered 20/4, 2016 at 4:35 Comment(2)
Nice story. So the OP would have to check for any occurrence of "D" charachter to definitively state the cell content is numericStereobate
nice story indeed, I never noticed this behavior and would be completely unable to explain itThayne

© 2022 - 2024 — McMap. All rights reserved.