Never Was Good At Math...

Results 1 to 6 of 6

Thread: Never Was Good At Math...

  1. #1
    BillyThekid Guest

    Default Never Was Good At Math...

    I&#039ve got a problem adding two variables from a db together.<BR><BR>Should be simple - it works when I multiply the values, but not when I add them (replacing the + with a *). Here&#039s the code:<BR><BR>&#060;%= (ShipSet1.Fields.Item("FIRSTITEM").Value) * (ShipSet1.Fields.Item("MOREITEM").Value)%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Never Was Good At Math...

    depending on whether you use JScript or VBScript, you need to parseInt() or CInt() them<BR><BR>if they&#039re floating point, use parseFloat() or CDbl()<BR><BR>j

  3. #3
    Billy TheOldFart Guest

    Default Probably not math...

    ...I bet that you are getting a string concatenation out of the + operator instead of addition, right?<BR><BR>That is, if the first value is 17.3 and the second is 22.9, I&#039ll bet you are getting 17.322.9, right?<BR><BR>Good old VBS just tries too hard sometimes.<BR><BR>How about:<BR><BR>&#060;% = CDbl(ShipSet1("FIRSTITEM")) + CDbl(ShipSet1("MOREITEM")) %&#062;<BR><BR>Does that work?<BR><BR>Bill Wilkinson

  4. #4
    BillyTheKid Guest

    Default RE: Probably not math...

    Nice one - worked a treat, now for part two:<BR><BR>I actually want to do this calculation:<BR><BR>FIRSTITEM + (MOREITEM*CARTQUANT)<BR><BR>Ive tried this:<BR>Response.Write(CDbl(ShipSet1("FIRSTITEM") ) + <BR>(CDbl(ShipSet1("MOREITEM"))*(Cart1.GetItemCoun t()))<BR><BR>Do I need Cdbl again, or is the parentheses wrong?<BR>

  5. #5
    Join Date
    Dec 1969

    Default RE: Probably not math...

    Well you had one extra set of parens in there (Response.Write is a SUB, not a FUNCTION, and so does not need parens for its argument). And then you have another extra set of parens around the last term of the expression. But neither of those would matter. <BR><BR>Are you asking what is the *minimum* you need to do? I would *expect*:<BR><BR>Response.Write CDbl(ShipSet1("FIRSTITEM")) + ShipSet1("MOREITEM") * Cart1.GetItemCount()<BR><BR>After all, the result of the multiplication *must* be a number, so no need to force it to a number with CDbl. And by making sure the first term is interpreted as a number, I think that is all you need.<BR><BR>It is *also* possible you can get rid of CDbl if you put in the one set of parens I said you didn&#039t need:<BR><BR>Response.Write ( ShipSet1("FIRSTITEM") + ShipSet1("MOREITEM") * Cart1.GetItemCount() )<BR><BR>But try that one out...don&#039t rely on me. VBS has some funny rules internally.<BR><BR><BR><BR><BR>

  6. #6
    BillyTheKid Guest

    Default RE: Probably not math...

    Excellent - worked a treat.<BR><BR>BillyTheOldFart proves that age is everything!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts