Addition When Null value is present

S

shankwheat

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
 
D

Darko

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)...
 
R

ron.h.hall

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top