The NoteTab Clips List is a Public Group with 2007 members.
 The NoteTab Clips List

 Public Group,
 2007 members
Primary Navigation
Re: [Clip] isnumber function
Expand Messages
 0 Attachment
So I say to self, "self, if you multiply the item by 100, that should
move the decimal out of the way and get better results." Self was wrong
... why is x * 1 = 0??
anyway this answer didn't work ...
new clip:
^!Jump Doc_Start
:repeat
^!Select Eol
^!Set %test%="^$Calc(^$GetSelection$*100)$"
^!If "^$IsNumber("^%test%")$" = "0" notnum
^!If "^$IsNumber("^%test%")$" = "1" num
^!Info [C]we should never get here ... everything either is or is not a
number
:notnum
^!Info [C]*^%test%* is NOT a number
^!Goto torepeat
:num
^!Info [C]*^%test%* IS a number
^!Goto torepeat
:torepeat
^!Jump +1
^!Goto repeat
New test list:
1
10
.10
x
word
1word
1,00,00.10
1.1
5.2
1,000.50
1,000
200
7.3546
Results:
1 number
10 number
.10 number
x number!
word not number
1word not number
1,00,00.10 number!
1.1 number
5.2 number
1,000.50 number
1,000 number
200 number
7.3546 number 0 Attachment
Don wrote:>I am surprised to find how it works because I think it only works on
Been there. In fact I found my post  from 2001. Jody confirmed number =
>integers and not decimals, etc.
integer. English question: what do you guys, in daily speech, call
"numbers" that are not integers? Honest question, I really don't know.
Anyway, I think you have to do some simple calculation on the questionable
number, get rid of the decimals and THEN test if it is a number.
^!If ^$IsNumber("^$Calc(^$GetSelection$*1;0)$")$ = 1 num else notnum
:num
^!Info It's a number!
^!Goto end
:notnum
^!Info Not a number.
This all is a little hairy. $IsAlpha()$ returns true only for real letters
aö. Put as much as period in the mix and it returns false.
Lotta 0 Attachment
loro wrote:> Don wrote:
Loro,
>> I am surprised to find how it works because I think it only works on
>> integers and not decimals, etc.
>
> Been there. In fact I found my post  from 2001. Jody confirmed number =
> integer. English question: what do you guys, in daily speech, call
> "numbers" that are not integers? Honest question, I really don't know.
>
> Anyway, I think you have to do some simple calculation on the questionable
> number, get rid of the decimals and THEN test if it is a number.
>
> ^!If ^$IsNumber("^$Calc(^$GetSelection$*1;0)$")$ = 1 num else notnum
Thanks so much for the response. I think I vaguely remember that
discussion. I call anything that is a number a number in English. That
function should say tells you if it is an integer number ....
I need to tell if something is a number.
Numbers are:
d
d.ddd
dd.dd
d,ddd.dd
ddd,ddd,ddd.dd
d,ddd
etc.
where d is an integer.
Numbers are not:
d.dd.dd
d,dd,ddd,ddd.dd
etc.
you need only one decimal
all characters must be either number 09, period/decimal/fullstop  but
only one of them, and commas to divide numbers at each third character
left of the decimal.
Another bug: multiply x*1=0
Why would that be? The result is that because 0 is an integer ... x is
a number if you use your calculation method! It doesn't have to be an x
either, I tried a c and same result ...
So I sat down and wrote a whole big clip for it ... it seems to be
working on my pattern ... for this list:
1,000.50
1,000
1,000.507
1,000,100
1,000
1,00,00.10
200
1
.10
10
10.10
10.7856
x
word
1word
1.1
5.2
7.3546
^!Jump Doc_Start
^!ClearVariable %decplace%
^!ClearVariable %commacheck%
:repeat
^!Select Eol
^!Set %test_variable%="^$GetSelection$"
;quick test if is an integer ... call it a num and go on
^!If "^$IsNumber(^%test_variable%)$" = "1" num
;next lets find out if we have just one decimal
^!If ^$StrCount(".";"^%test_variable%";false;false)$ > 1 notnum
;have either one or none decimals remove it and test
;get index of the decimal or set it to full length otherwise
^!Set %decplace%="^$StrPosRight(".";"^%test_variable%";false)$"
^!If ^%decplace% > 0 skip
^!Set %decplace%=^$Calc(^$StrSize("^%test_variable%")$+1)$
^!Set %test_variable%=^$StrReplace(".";"";"^%test_variable%";false;false)$
^!If "^$IsNumber(^%test_variable%)$" = "1" num
;next lets find out how many commas we have
^!Set %commas%=^$StrCount(",";"^%test_variable%";false;false)$
;if there are no commas, then we don't have a number
^!If ^%commas% = 0 notnum
;check placement of commas
^!Set %commacheck%="^$Calc(^%decplace%4)$"
:commas
^!If "," <> "^$StrIndex("^%test_variable%";^%commacheck%)$" notnum
^!Dec %commas%
^!If "^%commas%" = "0" removecommas
^!Set %commacheck%="^$Calc(^%commacheck%4)$"
^!Goto commas
:removecommas
^!Set %test_variable%=^$StrReplace(",";"";"^%test_variable%";false;false)$
^!If "^$IsNumber(^%test_variable%)$" = "1" num ELSE notnum
^!Info [C]we should never get here ... everything either is or is not a
number
:notnum
^!Info [C]*^%test_variable%* is NOT a number
^!Goto torepeat
:num
^!Info [C]*^%test_variable%* IS a number
^!Goto torepeat
:torepeat
^!Jump +1
^!Goto repeat
Results:
1,000.50 is
1,000 is
1,000.507 is
1,000,100 is
1,000 is
1,00,00.10 IS NOT
200 is
1 is
.10 is
10 is
10.10 is
10.7856 is
x IS NOT
word IS NOT
1word IS NOT
1.1 is
5.2 is
7.3546 is
Very odd and a lot of work. Now I need to make this essentially a
subroutine clip where I pass a number to it and have it give alert if
not number. ... hmmm
Thanks again Lotta,
Don 0 Attachment
Don wrote:> I call anything that is a number a number in English. That
Oh. Clear as mud! Thank you.
>function should say tells you if it is an integer number ....
>Another bug: multiply x*1=0
You are right. How strange. Bet there is a logical explanation as usual but
>Why would that be? The result is that because 0 is an integer ... x is
>a number if you use your calculation method! It doesn't have to be an x
>either, I tried a c and same result ...
I can't guess what it is.
ln() seems to work more as expected than multiplication. If I add that it
seems to work correctly.
^!If ^$IsNumber("^$Calc(ln(^$GetSelection$)*1;0)$")$ = 1 num else notnum
Lotta 0 Attachment
Don,
It isn't only multiplication. A single letter az always is 0. Anyone
knows why this is?
a+1=1
a*1=0
a/1=0
a^1=0
1^a=1
a*a=0
For example these return an error, same as they do if 0 is used instead of a.
1/a=[error]
ln(a)=[error]
So this would work too.
^!If ^$IsNumber("^$Calc(1/^$GetSelection$;0)$")$ = 1 num else notnum
Now the question is  why is it this way?
Lotta 0 Attachment
I don't have any knowledge on this, just thinking out loud.
I would say the 'a' is interpeted as not numeric and given a binary value of zero.
Possibly the letter 'a' needs a declaration to show it's a variable instead of a letter?
John Wallace
Pontiac Power RULES !!!
www.wallaceracing.com
Subject: Re: [Clip] isnumber function  calculating with letters
Don,
It isn't only multiplication. A single letter az always is 0. Anyone knows why this is?
a+1=1
a*1=0
a/1=0
a^1=0
1^a=1
a*a=0
For example these return an error, same as they do if 0 is used instead of a.
1/a=[error]
ln(a)=[error]
So this would work too.
^!If ^$IsNumber("^$Calc(1/^$GetSelection$;0)$")$ = 1 num else notnum
Now the question is  why is it this way?
Lotta 0 Attachment
> ln() seems to work more as expected than multiplication. If I add that it
Hi Lotta,
> seems to work correctly.
>
> ^!If ^$IsNumber("^$Calc(ln(^$GetSelection$)*1;0)$")$ = 1 num else notnum
The above fails on this example: "1,00,00.10"
Well I guess we could argue that is a number (begging that question
again I suppose). At best, I would suggest that it is a misformed
number. I don't know if I would have cared ... but for trying a bunch
of things it may not have occurred to me to check such a thing.
What happens if you divide by a letter ... is that division by zero? :)
By the way using this method, "1.10.10", is not a number, so I think
that more than one period/decimal/fullstop is bad, but placement of
commas is apparently ignored.
In an effort to test that theory I then used this: "1,,,,,,,,,,,1".
Good news! It is a number ;)
Thanks to all who contributed.
BTW here is a post from Alan that got lost in cyberspace somewhere:
Hi Don,
I'm wonder if the period and the comma happen to also fit within the
other, the corresponding (what is it, the getascii function or is it
IsAscii function)
(there are two functions of which that each does what the other doesn't,
IsNumber is one of these two)
IOW the conterpart to IsNumber
period and comma be found in "not number" (in sentences) too.
But, yes, given sufficient parsing ability/intelligence, I agree with
you on integers versus decimals.
I suppose in the meantime, may need to pre parse, rounding off to rid of
period and eliminate commas if they exist.
Alan. 0 Attachment
Don wrote:>The above fails on this example: "1,00,00.10"
Come on! That isn't a (correctly written) number any way you see it. A
writing convention maybe, but would you write it like that using a
calculator? We use to write "money" like this: "10:95" (where you would
write 10.95). That doesn't work either. :)
Lotta 0 Attachment
loro wrote:> Don wrote:
I think we agree then :)
>> The above fails on this example: "1,00,00.10"
>
> Come on! That isn't a (correctly written) number any way you see it. A
> writing convention maybe, but would you write it like that using a
> calculator? We use to write "money" like this: "10:95" (where you would
> write 10.95). That doesn't work either. :)
>
> Lotta
>
I probably didn't mean what I said or say what I meant. By fails I
meant that it shows it to be a number when I would argue it "isn't" a
number. I would have wanted it to say "not a number" but is said "is a
number" when I put it to the ln() test. So I would argue while better
than without that method that the method did not work to find well
formed numbers. We would also agree I think that 1,,,,,,1 isn't a
number, but that method found it to be one.
I am actually working on a European clip, so I have converted commas to
decimals so they are in my way of thinking before I test them. There
they say 10,95 vs my 10.95 vs your (now outdated) 10:95. I used
strreplace to convert it to my "proper" number formula. Then I wanted
to test it to be sure it was good. 0 Attachment
Don:>I am actually working on a European clip, so I have converted commas to
"My" Notetab handles comma as well as period as decimal point. I don't know
>decimals so they are in my way of thinking before I test them. There
>they say 10,95 vs my 10.95 vs your (now outdated) 10:95. I used
>strreplace to convert it to my "proper" number formula. Then I wanted
>to test it to be sure it was good.
if that is programmed in Notatab or if it in some way pick the comma up
from my system. I have some other (not swedish) programs that demand that I
use comma, just because of my locale. Very irritating. I'm now used to
period, so I get it wrong all the time.
But I meant numbers like this one: 1,00,00.10. As I see it there are two
too many, either you use comma or period. ;)
It's odd though. I also feel that what's not numeric should be alpha. And
did we figure out why letters, mathematically, are zero? ;o)
Lotta 0 Attachment
loro wrote:> It's odd though. I also feel that what's not numeric should be alpha. And
Lotta,
> did we figure out why letters, mathematically, are zero? ;o)
>
> Lotta
The IsNumber function is a True/False test. Either the selected
information is a number or it is not. The Clip Help indicates that it
returns 1 for a number and 0 if it is not. It must assume decimal
numbers, there is no option to consider Hexadecimal. But octal and
binary values that have the same characters to represent decimal numbers
would evaluate to numbers, if there is no character as part of the
number indicating something other than decimal.
I have not tested regionspecific delimiters for thousands and decimals,
but it should rely on the regional settings to determine if certain
values are numbers or not. If it does not fit the pattern for thousands
and decimals, then it must be a problem with the infamous input control.
Larry Hamilton
Kairos Computer Solutions
http://www.kairoscomputers.com/
Sales Affiliate for Grisoft AntiVirus 0 Attachment
Larry Hamilton wrote:> loro wrote:
Hi Larry,
>
>>It's odd though. I also feel that what's not numeric should be alpha. And
>>did we figure out why letters, mathematically, are zero? ;o)
>>
>>Lotta
>
> Lotta,
>
> The IsNumber function is a True/False test. Either the selected
> information is a number or it is not. The Clip Help indicates that it
> returns 1 for a number and 0 if it is not. It must assume decimal
> numbers, there is no option to consider Hexadecimal. But octal and
Of the things we tested only the following were numbers (according to
isnumber):
a. an integer
b. any single letter of the alphabet (I consider this to be a bug)
The following were not numbers:
a. any decimal number
b. any mixed characters other than a single alphabetic character
c. any number with commas in it for example 1,000
So isnumber isn't isnumber, it is isinteger (with an odd twist of single
alphabetic characters tossed in).
Hopefully this can be fixed in version 4.96. 0 Attachment
Larry Hamilton wrote:>The IsNumber function is a True/False test. Either the selected
Except if it's a single letter! :)
>information is a number or it is not.
>I have not tested regionspecific delimiters for thousands and decimals,
It works, as I can use both period and comma.
>but it should rely on the regional settings to determine if certain
>values are numbers or not. If it does not fit the pattern for thousands
>and decimals, then it must be a problem with the infamous input control.
The problem is that a single alphabetic character returns true when tested
with $IsNumber$, as Don discovered. What more is, the letter seems to
evaluate to 0. Or that's what we thought yesterday. But I tried to
calculate with all the letters in the alphabet and it turns out this only
"works" with the letters a, b, c, d, e, t, x and y. The others return an
error, as we expected they all would ("expression could not be evaluated").
But it doesn't stop here. Take a look at this. Just calculate with Ctrl+E,
no clip needed.
a*2=0
b*2=0
c*2=0
d*2=0
e*2=0
t*2=0
x*2=0
y*2=0
2^a=1
2^b=1
2^c=1
2^d=1
2^e=1
2^t=1
2^x=1
2^y=1
The letters act as they were zero. But look what happens with e here...
a+2=2
b+2=2
c+2=2
d+2=2
e+2=0
t+2=2
x+2=2
y+2=2
a2=2
b2=2
c2=2
d2=2
e2=0
t2=2
x2=2
y2=2
??????????????
Lotta 0 Attachment
As we all know, the letter e is the most popular letter, so it demands
to be treated differently during negotiations, don't you think?
> The letters act as they were zero. But look what happens with e here...
>
>
> a+2=2
> b+2=2
> c+2=2
> d+2=2
> e+2=0
> t+2=2
> x+2=2
> y+2=2
>
> a2=2
> b2=2
> c2=2
> d2=2
> e2=0
> t2=2
> x2=2
> y2=2 0 Attachment
Don wrote:>As we all know, the letter e is the most popular letter, so it demands
I think it's nothing less than an insult that I can't calculate with å, ä
>to be treated differently during negotiations, don't you think?
and ö, that's what I think. I'll probably write to Jody about this. I
demand that åäö calculation will be properly implemented in the next version!
Lotta  who is joking (better add that! ;o)) 0 Attachment
Don  htmlfixit.com wrote:> As we all know, the letter e is the most popular letter, so it demands
I'd like to buy a Q. ;)
> to be treated differently during negotiations, don't you think?
I do not know if this behavior for IsNumber is a clip language bug or a
problem with the infamous input control. I do not need this function too
often, so personally not a big problem, but it should be fixed.
Larry 0 Attachment
Don  htmlfixit.com wrote:
> Larry Hamilton wrote:
I think the problem is with the definition of IsNumber in Help. It
> > loro wrote:
> >
> >>It's odd though. I also feel that what's not numeric should be
> alpha. And
> >>did we figure out why letters, mathematically, are zero? ;o)
> >>
> >>Lotta
> >
> > Lotta,
> >
> > The IsNumber function is a True/False test. Either the selected
> > information is a number or it is not. The Clip Help indicates that it
> > returns 1 for a number and 0 if it is not. It must assume decimal
> > numbers, there is no option to consider Hexadecimal. But octal and
>
> Hi Larry,
>
> Of the things we tested only the following were numbers (according to
> isnumber):
> a. an integer
> b. any single letter of the alphabet (I consider this to be a bug)
>
> The following were not numbers:
> a. any decimal number
> b. any mixed characters other than a single alphabetic character
> c. any number with commas in it for example 1,000
>
> So isnumber isn't isnumber, it is isinteger (with an odd twist of single
> alphabetic characters tossed in).
takes an argument of "Value" and then refers to "Value" as the
"specified text". A better definition might be:
$IsNumber*("Str")$ *Returns 1 if Str contains only digits 0 through 9,
and 0 if it does not.
This explains what you observe. The fact that these numbers are
integers is just a coincidence. This definition also corresponds more
closely to the definition of IsAlpha.
It also might have avoided this whole thread. :)
> Hopefully this can be fixed in version 4.96.
>
>
> Fookes Software: http://www.fookes.us, http://www.fookes.com
> Fookes Software Mailing Lists: http://www.fookes.us/maillist.htm 0 Attachment
> I think the problem is with the definition of IsNumber in Help. It
Your definition would have indeed been better than the one provided ...
> takes an argument of "Value" and then refers to "Value" as the
> "specified text". A better definition might be:
>
> $IsNumber*("Str")$ *Returns 1 if Str contains only digits 0 through 9,
> and 0 if it does not.
>
> This explains what you observe. The fact that these numbers are
> integers is just a coincidence. This definition also corresponds more
> closely to the definition of IsAlpha.
>
> It also might have avoided this whole thread. :)
but I think it is more accurate to say integers (defined as all whole
numbers positive AND NEGATIVE and zero:
http://en.wikipedia.org/wiki/Integer ). Your definition forgot the
negative sign ... that is not a 09 character ... and can only appear
immediately preceeding the number:
^!Info [C] minus 5  ^$IsNumber("5")$
^!Info [C] 5 minus  ^$IsNumber("5")$
^!Info [C] 5 minus 5  ^$IsNumber("55")$
This tread would have still been necessary because what I needed to do
was test if something was a number in this format ([brackets mean
optional] and ... ellipses means one or more):
[#...][,][##]#[.][#...]
As isnumber didn't cover my situation ... I had to come up with a way to
do it.
Is is possible to test if something is a "number" with a regex?
Rules:
1. either one or no decimal point, but there can be any number of proper
characters before and after the decimal
2. comma's are permitted but not required, but may only be present with
three proper characters to the right of each comma and left of the
decimal (or implied decimal if it is an integer)
3. proper characters are 09, an no other characters are permitted
except for rule 1 (decimal point) and rule 2 (properly placed commas)
I wrote a clip function to do it, but if there is a regex that would do
it quicker ...
I just did this:
a+b+c+d+e+t+x+y=0
But the fact that those letters for some reason have a numeric value of
zero when used in calculations DOES NOT make them numbers per isnumber
when not used in calculations, as each of the following tests negative:
^!Info [C]abcdetxy ^$IsNumber("abcdetxy")$
^!Info [C]a ^$IsNumber("a")$
^!Info [C]aa ^$IsNumber("aa")$
^!Info [C]e ^$IsNumber("e")$
But when we use calc, we are all over the place ...
^!Info [C]abcdetxy ^$IsNumber("^$Calc(abcdetxy)$")$
^!Info [C]a ^$IsNumber("^$Calc(a)$")$
^!Info [C]aa ^$IsNumber("^$Calc(aa)$")$
^!Info [C]a*a ^$IsNumber("^$Calc(a*a)$")$
^!Info [C]e ^$IsNumber("^$Calc(e)$")$
Anyway, I am enjoying the tread and hope deep in my heart that this bug
just might be the catalyst to get Eric coding either an update or better
yet, a version 5. As I said a few months back though, I am not sure a
version 5 is really going to happen and nobody has told me I am wrong by
giving me any milestones, targets or goals. I'd settle for 4.96 with
this bug fixed and isnumber better defined in help ;) 0 Attachment
Don,
You could try this...
It fetches 4.96 as well as 5.0.
And:
123,4234,976.345
4234,976.345
234,976.345
4234976.345
4234976345
1
(\d+,)*\d+(\.)*\d*
Hugo 0 Attachment
Hi Lotta and All,
>Don wrote:
LOL! Actually, I have been trying to follow this thread, but my
>> As we all know, the letter e is the most popular letter, so it
>> demands to be treated differently during negotiations, don't
>> you think?
>
>I think it's nothing less than an insult that I can't calculate
>with å, ä and ö, that's what I think. I'll probably write to Jody
>about this. I demand that åäö calculation will be properly
>implemented in the next version!
time is limited. I have sent posts to me to file it as a bug. I'm
sure Eric will take it into consideration in the infamous
4.96/5.0/6.0 release. I'll push to get the extended characters
added along with giving "e" preference Don, but only after "E". :)
>Lotta  who is joking (better add that! ;o))
Happy Topics,
Jody
The NoteTab OffTopic List
mailto:ntbOffTopicSubscribe@yahoogroups.com
mailto:ntbOffTopicUnSubscribe@yahoogroups.com
All Fookes Software mailing lists and more...
http://www.fookes.us/maillist.htm
http://www.fookes.us/redir http://www.cleanfunnies.com/
http://www.notetab.net/ http://www.sojourner.us/software 0 Attachment
Hi Don:
On Thu, 09 Mar 2006 08:46:18 0500, Don  htmlfixit.com wrote:
> But when we use calc, we are all over the place ...
> ^!Info [C]abcdetxy  ^$IsNumber("^$Calc(abcdetxy)$")$
> ^!Info [C]a  ^$IsNumber("^$Calc(a)$")$
> ^!Info [C]aa  ^$IsNumber("^$Calc(aa)$")$
> ^!Info [C]a*a  ^$IsNumber("^$Calc(a*a)$")$
> ^!Info [C]e  ^$IsNumber("^$Calc(e)$")$
Not quite correct Don as not all of your Calc statements are valid. Try the
following to see what I mean.
^!Info [C]abcdetxy  ^$IsNumber("^$Calc(abcdetxy+0)$")$ 
^$Calc(abcdetxy+0)$
^!Info [C]a  ^$IsNumber("^$Calc(a+0)$")$  ^$Calc(a+0)$
^!Info [C]aa  ^$IsNumber("^$Calc(a+a)$")$  ^$Calc(a+a)$
^!Info [C]a*a  ^$IsNumber("^$Calc(a*a)$")$  ^$Calc(a*a)$
^!Info [C]e  ^$IsNumber("^$Calc(e+0)$")$  ^$Calc(e+0)$
Charlie
Charles M. Raine,
Winnipeg. MB R3P 0W3
Your message has been successfully submitted and would be delivered to recipients shortly.