What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » help with convert strings

help with convert strings
Author: Message:
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: help with convert strings
quote:
var number1='5';
var number2='4';
var result=number1+number2;
...
but the result is 54, and not 9. why ?
To answer your question for your specific example: because you have indicated the values are strings by using single quotes.  Remove the quotes and try the following:
code:
var number1 = 5;
var number2 = 4;
var result = number1 + number2;
Now you should be getting 9 as the result. 

Of course, you won't always be able to do this when your values are coming from somewhere else and happen to be strings.  When that happens you will want to check out parseInt() and parseFloat():
code:
var number1 = '5';
var number2 = '4';
var result = parseInt(number1) + parseInt(number2);
This should yield 9 as well.
08-08-2010 06:00 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
help with convert strings - by ChaosMaker on 08-08-2010 at 04:23 AM
RE: help with convert strings - by Adeptus on 08-08-2010 at 06:00 AM
RE: help with convert strings - by Spunky on 08-08-2010 at 01:34 PM
RE: help with convert strings - by NanaFreak on 08-08-2010 at 02:19 PM
RE: help with convert strings - by Spunky on 08-08-2010 at 07:29 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On