Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread IsNumber function, NaN and IsNaN.
Wed, Oct 30 2013 5:33 AMPermanent Link

E.B

Hello,


I'm trying to code an "IsNumber(S:String):Double"  function with EWB. First idea is testing every characters in S.

But EWB seems to have an interesting way to deal with not-a-number strings with FloatToStr.

If S contains "," it is  rouding to an integer.
If S contains "." it is rouding to a double.

If S's not a number it is set to "NaN".  So testing if FloatToStr return "NaN" or not is a way to test if it is a valid float number.

But how can I test if a double is equal to NaN ?

I didn't see "IsNan" function and compiler refuse "if x=NaN then".

Regards.

F.




Tue, Nov 5 2013 3:24 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eric,

<< I'm trying to code an "IsNumber(S:String):Double"  function with EWB.
First idea is testing every characters in S.

But EWB seems to have an interesting way to deal with not-a-number strings
with FloatToStr. >>

EWB doesn't actually perform the conversion - the conversion is performed by
the Javascript runtime library.

<< If S contains "," it is  rouding to an integer.
If S contains "." it is rouding to a double.

If S's not a number it is set to "NaN".  So testing if FloatToStr return
"NaN" or not is a way to test if it is a valid float number.

But how can I test if a double is equal to NaN ?  >>

Could you please post the code that you're using ?

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Sun, Nov 10 2013 4:09 AMPermanent Link

E.B

Function Isnum(S:String):Boolean;
Var
X: double;

Begin

X:=StrToFloat(S);

Now I want to test if S is "Not a Number" (NaN),  Tim.

end;

I solved the problem writing a lot a test (S in ['0'..'9','-','+','.'] etc.)
But I would to use a IsNum function that is using StrToFloat function.





"Tim Young [Elevate Software]" wrote:

Eric,

<< I'm trying to code an "IsNumber(S:String):Double"  function with EWB.
First idea is testing every characters in S.

But EWB seems to have an interesting way to deal with not-a-number strings
with FloatToStr. >>

EWB doesn't actually perform the conversion - the conversion is performed by
the Javascript runtime library.

<< If S contains "," it is  rouding to an integer.
If S contains "." it is rouding to a double.

If S's not a number it is set to "NaN".  So testing if FloatToStr return
"NaN" or not is a way to test if it is a valid float number.

But how can I test if a double is equal to NaN ?  >>

Could you please post the code that you're using ?

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Nov 14 2013 3:08 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eric,

<< Now I want to test if S is "Not a Number" (NaN),  Tim. >.

Use this:

uses WebDOM;

Function Isnum(S:String):Boolean;
Var
X: double;

Begin

X:=StrToFloat(S);

if isNaN(X) then
  Result:=False
else
  Result:=True;

end;

Tim Young
Elevate Software
www.elevatesoft.com
Image