471,887 Members | 1,056 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Addition When Null value is present

I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null
This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
{
alert("true");
TotalScore = TotalScore + 2.5;
}

If I do this then it works fine.

CEOBonusValue == 550000
CEONonEqIncentCompHidden == 0

I'm not sure how to handle this. I need to keep the null values in my
database.

Thanks

May 25 '07 #1
2 2067
On May 25, 7:06 pm, shankwheat <evanbu...@gmail.comwrote:
I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null

This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
{
alert("true");
TotalScore = TotalScore + 2.5;
}

If I do this then it works fine.

CEOBonusValue == 550000
CEONonEqIncentCompHidden == 0

I'm not sure how to handle this. I need to keep the null values in my
database.

Thanks
Wait a minute, how does this javascript piece of code actually gets
this string "null", if the "null" value travels through server-side
code, and gets printed to javascript. What I mean is, if you get the
value from db in e.g. php, can't you just check immediately if the
value is null, and if it is - print it to javascript as 0? Why do you
print "null" to javascript, if you can't handle it well?

Another thing, I don't know if it's bad syntax just here in the thread
or you did the same in your scripts, but it seams you've been mixing
"==" and "=" operators... I see the piece of code:
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null
- the second line isn't of much use, it should be ...dden = null,
not ...den == null (because in this way you don't actually assign it,
but just compare it)...

May 25 '07 #2
On May 25, 10:06 am, shankwheat <evanbu...@gmail.comwrote:
I'm having trouble adding two values together when one of them has a
null value

// These two values come from a database
CEOBonusValue = 550000
CEONonEqIncentCompHidden == null

This should alert to true but doesn't

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
CEONonEqIncentCompHidden < 2264001)
The unary + operator will convert a null to numeric zero. E.g., you
could write:

if (MarketCapHidden=="Large Caps" && CEOBonusValue +
+CEONonEqIncentCompHidden < 2264001)

to cover off the problem as described (misuse of == notwithstanding).

--
../rh

May 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.