On 08.09.21 23:08, K.S. Bhaskar wrote:
> I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.
>
> What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.
In addition to what others already wrote, you have to clarify the
"string is a number" definition:
- do you consider a string like "00123" or "123.4500" as numbers?
- do you consider a string like "-12" or "---123" or "-+-12" as numbers?
I would say, for a "string" to be a number:
- the string must contain at least one digit
- a period (if present) must be followed by a digit
- during the string to number conversion, all the characters
of that string must be consumed as part of the resulting number
For example:
"123.40" is a number
"123.4X" is not a number, "x" wasn't used to build the value 123.4
"123.,45" is not a number, "," and the digits 4 and 5 were not used
"+-+087.90" is a number
"12." is (not?) a number (a "." should be followed by a digit - or not?)
Also, in US, ".34" is the canonical form for european "0.34". Some 30-40
years ago, I worked with a MUMPS implementation where +".34" returned 0
because of the missing leading zero...
Regards
Julius
--
An old Windows has old security holes.
A new Windows has new security holes.
Another OS has other security holes.
For safety you must care yourself.