[Javascript] type casting...

Peter Brunone peter at brunone.com
Mon Jun 30 10:20:32 CDT 2003


   I think what J.R. is looking for is 

foo = parseInt(foo);

Since browser scripting languages are generally type-free (all variables default to type variant), it can be a little confusing to seasoned programmers... and sometimes, their questions about type casting can be confusing to those of us who only use client-side scripting :)

Cheers,

Peter

---------- Original Message ----------------------------------
From: "Tim Makins" <spindrift at oceanfree.net>

>To change a string to a number, I use this:
>
>foo = foo - 0;
>
>HTH Tim in Ireland.
>PS What on earth does your subject line mean ?
>
>  ----- Original Message ----- 
>  From: J.R. Pitts 
>  To: javascript at LaTech.edu 
>  Sent: 28 June 2003 04:34
>  Subject: [Javascript] type casting...
>
>
>  I don't usually do javascript, but every now and then....
>
>  I am doing some time math. I use the following statement to convert a time string (ie...15:30) to a total number of minutes (ie..930)
>
>   endMinutes=endTime.substring(0,2)*60 + endTime.substring(3,5)*1
>
>
>  I have to use the ending "*1" to cast the the ending string to a number, so that I get '930' instead of a string concatenation (90030)
>
>
>
>  Works fine, but what is the proper javascript way to do this?
>
>  Thanks,
>
>  J.R. 
             


More information about the Javascript mailing list