Forums > Javascript

typecheck for arguments

September 14, 2006 | 9:42 am

I want a different behaviour for differnt types of arguments. Is there a
way to determine if an argument to a JSUI is a float or an integer?

Stefan


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


September 14, 2006 | 12:26 pm

On 14 sept. 06, at 11:42, Stefan Tiedje wrote:

> I want a different behaviour for differnt types of arguments. Is
> there a way to determine if an argument to a JSUI is a float or an
> integer?

Hi Stefan,

I don’t think this is possible. At least not in the JavaScript world,
because ints and floats are simply "numbers" (64 bits floating). It
could be nice through.

Best,
ej


September 25, 2006 | 11:23 am

hi, a possible hack is to turn the number into a string and then regExp to find if there is a point==float, this can get expensive.


September 26, 2006 | 12:47 pm

i guess you could always take the number and compare it to itself
passed into Math.floor()

FYI, if you check the type of a float or int (using typeof(…)) it
comes up as "number". not very useful for testing int vs. float.

otherwise, i assume you’ll have to parse it for the "." like yair wrote.

best
evan

On Sep 25, 2006, at 12:23 PM, yair reshef wrote:

>
> hi, a possible hack is to turn the number into a string and then
> regExp to find if there is a point==float, this can get expensive.
>
>


Viewing 4 posts - 1 through 4 (of 4 total)