help with numbers !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Smith

    help with numbers !

    Hi,

    I'm just trying to work out the postage costs for a shopping cart and for
    some reason (possibly me being silly) i can't get the following to work :

    Dim strWeight3, strWeight4
    strWeight3 = "950"
    If strWeight3<="10 00" Then strWeight4="3.3 2" Else strWeight4="7.5 0"
    Response.Write( strWeight3 & "&nbsp;/&nbsp;")
    Response.Write( strWeight4)


    So the weight's in Grammes, If it's over 1000g then the price is 7.50
    otherwise it's 3.32.
    The problem is this will only return the figure 7.50 for some reason
    ............... ..

    Any pointers appreciated.

    Thanks


  • Brian Staff

    #2
    Re: help with numbers !

    John,
    [color=blue]
    > Dim strWeight3, strWeight4
    > strWeight3 = "950"
    > If strWeight3<="10 00" Then strWeight4="3.3 2" Else strWeight4="7.5 0"
    > Response.Write( strWeight3 & "&nbsp;/&nbsp;")
    > Response.Write( strWeight4)[/color]

    You are comparing two "strings" and so, "1000" is less that "950"

    Brian Staff

    Comment

    • Evertjan.

      #3
      Re: help with numbers !

      John Smith wrote on 30 jun 2003 in microsoft.publi c.inetserver.as p.general:
      [color=blue]
      > Just out of interest, i know that it won't work correctly if it was :
      >
      > If intWeight3 <"1000" Then....
      >
      > But why is this ?[/color]

      comparing two strings alphabetically:

      each character is compared by its ascii value,
      and strings from left to right,
      till there is a difference:

      "9" < "A"

      "A" < "a"

      "8" > "1"

      "abc1" < "abc2"

      "adc1" > "abc1"

      "bbb" > "abbb"

      "800" > "1000"


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      Working...