Re: Variables - Integer vs. Character
by Nathan Lyle <natlyle(at)nmu.edu>
|
Date: |
Wed, 14 Feb 2001 10:25:23 -0500 |
To: |
Jeremy Duncanson <aesic(at)softhome.net> |
Cc: |
hwg-techniques(at)hwg.org |
References: |
nmu |
|
todo: View
Thread,
Original
|
|
<Jeremy>
> add zero to your sum to force a string to be a number or
> add an empty string to force a number to become a string
>ie:
> i = totalCost + 0; // or
> i = totalCost + "";
>The former is what you could use now, but you might want to remember
>the latter for future use. In other languages, you could typecast
>the variable:
> i = (int)totalCost;
>Unfortunately, I can't remember if that works in javascript.
Typecasting doesn't work in Javascript as in other languages, to my
knowledge. Using a 0 or piece of string is what I had used in the past that
seemed to work, but didn't in this case.
I *did* figure out a solution, however. I had to use parseInt() on the
values from the form, before adding them to total. Plus, I had started off
a variable "base" but used quotes where I shouldn't. ( base="1025"; )
which of course made 1025 a string and not an int. Doh!
Just losing the quotes didn't work, I had to also use the parseInt(), but,
now it seems to be working.
Thanks for the suggestion though!
~Nathan Lyle (The Tragic Comedian Poet)
Email: natlyle(at)nmu.edu or jopling(at)geocities.com
Web: http://euclid.nmu.edu/~natlyle
Phone: 906-227-5736
"It is difficult to live in the present, ridiculous to live in the future,
and impossible to live in the past. Nothing is as far away as one minute
ago." - Jim Bishop
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA