Announcement

Collapse
No announcement yet.

Does 0 equal 0.00?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Does 0 equal 0.00?

    I was working on some template code, and I was surprised to see this conditional on the BASK and INVC pages:
    Code:
    <mvt:if expr="l.settings:item:price EQ '0' OR l.settings:item:price EQ '0.00' OR l.settings:item:price EQ 0.00 OR l.settings:item:price EQ 0">
    I thought the VM regarded all those as equivalent. Can someone please clarify?

    Thanks --
    Kent Multer
    Magic Metal Productions
    http://TheMagicM.com
    * Web developer/designer
    * E-commerce and Miva
    * Author, The Official Miva Web Scripting Book -- available on-line:
    http://www.amazon.com/exec/obidos/IS...icmetalproducA

    #2
    You are correct. I'm not seeing that anywhere in our base templates. Maybe a PS developer or 3rd party developer added it?
    David Carver
    Miva, Inc. | Software Developer

    Comment


      #3
      I saw it in a couple of places in this store, and I think I've seen it before in other stores, but don't recall where. Thanks for the clarification.

      Also, what's a "PS developer" please? I don't recognize that abbreviation.
      Kent Multer
      Magic Metal Productions
      http://TheMagicM.com
      * Web developer/designer
      * E-commerce and Miva
      * Author, The Official Miva Web Scripting Book -- available on-line:
      http://www.amazon.com/exec/obidos/IS...icmetalproducA

      Comment


        #4
        Professional Services at Miva.
        David Carver
        Miva, Inc. | Software Developer

        Comment


          #5
          Actually, its been there for years. I think at least since the first ready themes.

          PS = Professional Services

          And just for clarity, I believe that would be true (that they are all equal) only if the field type was a number. If the field type is text, then they are not the same.

          Bruce Golub
          Phosphor Media - "Your Success is our Business"

          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
          phosphormedia.com

          Comment


            #6
            The underlying data type does not matter. They are all the same and will all evaluate to true.
            David Carver
            Miva, Inc. | Software Developer

            Comment


              #7
              IIRC, the VM processes the comparison operators (LT, GT, EQ, LE, GE, NE) by first trying to do a numeric comparison. If either of the operands is not a valid number, then the VM switches to a string comparison. And for numeric-comparison purposes, empty-string is equivalent to zero, and all forms of zero -- string or numeric, with or without decimal point -- are equivalent.

              I suppose that, if you're doing an SQL query with a comparison in it, the behavior may be different, since the comparison is processed by the DB server, not the VM. But once you bring the data into Miva Script variables, the VM is in charge.
              Kent Multer
              Magic Metal Productions
              http://TheMagicM.com
              * Web developer/designer
              * E-commerce and Miva
              * Author, The Official Miva Web Scripting Book -- available on-line:
              http://www.amazon.com/exec/obidos/IS...icmetalproducA

              Comment


                #8
                This conditional simplifies the test by forcing a numeric comparison.

                Code:
                <mvt:if expr="(l.settings:item:price * 1) EQ 0) ">
                Zero Price
                </mvt:if>
                Ray Yates
                "If I have seen further, it is by standing on the shoulders of giants."
                --- Sir Isaac Newton

                Comment

                Working...
                X