What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Convert Boolean to Numeric?

Convert Boolean to Numeric?
Author: Message:
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
35 / Male / Flag
Joined: Mar 2004
RE: Convert Boolean to Numeric?
quote:
Originally posted by markee
quote:
Originally posted by phalanxii
I believe Math.abs(<boolean>) also does that.
This will give the absolute value of the number which is not what you want.  Boolean expressions are equivalent to 1 for true, 0 for null and -1 for false and thus you would have a problem where you couldn't tell the difference between true and false.  Even Spunky's code is incorrect because it misses the null possibility and false should be negate one not zero.  The proper methods would be either to use the parseInt method or multiply the boolean variable by 1 (or minus zero).  This is also the same when you try to convert a string to a number.
er what boolean is either 1 (true) OR 0 (false) theres no -1, its its null its not a boolean, its null :-/

Math.abs does exactly what he wants :-/

code:
Math.abs(true) == 1
Math.abs(false) == 0
Math.abs(null) == 0
Math.abs(undefined) == NaN

[Image: dt2.0v2.png]      Happy Birthday, WDZ
10-04-2007 02:21 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Convert Boolean to Numeric? - by stu on 10-03-2007 at 07:18 PM
RE: Convert Boolean to Numeric? - by Spunky on 10-03-2007 at 07:22 PM
RE: Convert Boolean to Numeric? - by stu on 10-03-2007 at 07:42 PM
RE: Convert Boolean to Numeric? - by markee on 10-03-2007 at 11:52 PM
RE: Convert Boolean to Numeric? - by phalanxii on 10-04-2007 at 12:33 AM
RE: Convert Boolean to Numeric? - by markee on 10-04-2007 at 12:44 AM
RE: Convert Boolean to Numeric? - by phalanxii on 10-04-2007 at 01:05 AM
RE: Convert Boolean to Numeric? - by deAd on 10-04-2007 at 01:22 AM
RE: Convert Boolean to Numeric? - by phalanxii on 10-04-2007 at 01:32 AM
RE: Convert Boolean to Numeric? - by deAd on 10-04-2007 at 01:37 AM
RE: Convert Boolean to Numeric? - by ShawnZ on 10-04-2007 at 02:04 AM
RE: Convert Boolean to Numeric? - by stu on 10-04-2007 at 03:04 AM
RE: Convert Boolean to Numeric? - by Spunky on 10-04-2007 at 11:51 AM
RE: Convert Boolean to Numeric? - by -dt- on 10-04-2007 at 02:21 PM
RE: Convert Boolean to Numeric? - by Matti on 10-04-2007 at 04:52 PM
RE: Convert Boolean to Numeric? - by markee on 10-04-2007 at 10:41 PM
RE: Convert Boolean to Numeric? - by Voldemort on 10-04-2007 at 11:01 PM
RE: Convert Boolean to Numeric? - by Spunky on 10-05-2007 at 12:40 AM


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