Published on InterSystems Developer Community (https://community.intersystems.com)

Home > How to distinguish whether a variable is a pure numeric string or a number, such as "123" and "123".

Question
Cryze Zhang · May 16, 2022

How to distinguish whether a variable is a pure numeric string or a number, such as "123" and "123".

HI Guys.

I want to know how to distinguish whether a variable is a pure numeric string or a number, such as "123" and "123".

I only know an inelegant way.

ClassMethod IsNumber(n)
{
	s ret=0
	try{
		s ret= $lb(n)=$lb(+n)
	}catch e{
		s ret=0
	}
	q ret
}

Is there any other way to implement it

#ObjectScript #Caché
Product version: Caché 2016.1
$ZV: Cache for Windows (x86-64) 2016.2 (Build 736U) Fri Sep 30 2016 11:46:02 EDT

Source URL:https://community.intersystems.com/post/how-distinguish-whether-variable-pure-numeric-string-or-number-such-123-and-123