To check whether value is numeric in LS, I would write the following code:
Dim strVal as String
Dim dVal as Double
strVal = doc.fldValue(0)
If IsNumeric(strVal) Then
dVal = cdbl(strVal)
End If
How would we achieve this within XPages? I just tried getItemValueString on a numeric field and it didn’t work. getItemValueDouble worked, but as we all know we cannot rely on that field value to be numeric (in case some rogue agent is ran and converts a field on a particular document to be a text field by mistake!), so how do we check whether it’s numeric or not in XPages? Is there an easy way to achieve this or do we have to use getItemValue and check through the vector object? Has anyone else noticed this?
Thanks.
In my experience when you are saving a numeric value it will be returned as a double value. If you want to be sure which datatype the .getitemvalue(“field”) value returns, you can use the .getClass() method on the returned value. for instance when you want to print it to the console:
or… you could just use
😉