Posts: 1622 Reputation: 50
36 / /
Joined: Jan 2006
RE: Convert Boolean to Numeric?
quote:Originally posted by -dt-
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