which datatype takes actuall value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh22
    Banned
    New Member
    • Sep 2007
    • 81

    which datatype takes actuall value

    Hi,
    in my database i gave a datatype as float so i entered a value as 3.10 but it taking as 3.1 and also i entered as 3.999 but it will taking as 4 how its possible
    which datatype store the actuall value
    ex : if i entered as 3.999 means it will as 3.999 only again if i given as 3.10 means it will take as 3.10 only
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    please find all the details here.

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      Originally posted by ganesh22
      Hi,
      in my database i gave a datatype as float so i entered a value as 3.10 but it taking as 3.1 and also i entered as 3.999 but it will taking as 4 how its possible
      which datatype store the actuall value
      ex : if i entered as 3.999 means it will as 3.999 only again if i given as 3.10 means it will take as 3.10 only

      use the datatype REAL

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        Actually, I am not really understanding your question because if you enter 3.10 then 3.1 IS the real value, try it on your calculator.
        So, if you want a variable number of decimal places then float is the correct type.
        If you enter 3.10 then the real value is 3.1 which is what float will store
        If you enter 3.199900 then the real value is 3.1999 which is what float will store.

        If you want to store the value exactly as it was entered then you will have to save it as a varchar.
        so if you enter 3.1000000 then it will be saved as 3.1000000

        All number types will remove the zeros on the end because they are unnecessary

        Comment

        • ganesh22
          Banned
          New Member
          • Sep 2007
          • 81

          #5
          Originally posted by OuTCasT
          use the datatype REAL
          hi,
          i used that one but its not working

          Comment

          • ganesh22
            Banned
            New Member
            • Sep 2007
            • 81

            #6
            Originally posted by Delerna
            Actually, I am not really understanding your question because if you enter 3.10 then 3.1 IS the real value, try it on your calculator.
            So, if you want a variable number of decimal places then float is the correct type.
            If you enter 3.10 then the real value is 3.1 which is what float will store
            If you enter 3.199900 then the real value is 3.1999 which is what float will store.

            If you want to store the value exactly as it was entered then you will have to save it as a varchar.
            so if you enter 3.1000000 then it will be saved as 3.1000000

            All number types will remove the zeros on the end because they are unnecessary
            Hi,
            if i take varchar means on searching its not getting all values

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              It means you have to convert the value you're searching.

              If this is for display purposes on your front-end, handle in on your front-end.

              -- CK

              Comment

              • Delerna
                Recognized Expert Top Contributor
                • Jan 2008
                • 1134

                #8
                Originally posted by ganesh22
                Hi,
                if i take varchar means on searching its not getting all values
                Yes, that is correct it won't bring back all the values.

                This is because the numbers 3.1 and 3.10 are exactly same number
                but the strings 3.1 and 3.10 are very different.
                As I said in my previous post, I really don't understand the question.
                Why does it matter that if you enter 3.10 and 3.1 is saved. They are both the same number. You may have a valid reason, I don't know.

                If you convert the varchar as ck suggests then the zero will be dropped again.
                If you keep the varchar idea then 3.1 and 3.10 won't match in a search.

                So at this point you are faced with a decision.
                All number types will drop zeros from the end of the decimal part. There is nothing you can do about that.
                So either
                1) you use decimal type, perhaps decimal(18,4) which means 4 decimal places.
                With that
                an entry of 3.1 will appear in queries as 3.1000
                an entry of 4.190 will appear in queries as 4.1900

                or

                2) You use some other number type such as float or real
                which means an entry of 3.10 will appear in queries as 3.1
                and an entry of 4.190 will appear in queries as 4.19
                or

                3) you use a varchar and come up with some tricky way to keep the number as string but still be able to search correctly.

                Perhaps you can select the field in your queries twice. Once for displaying the number as entered and the second one you convert it back to a number for your query searching.

                Comment

                • ganesh22
                  Banned
                  New Member
                  • Sep 2007
                  • 81

                  #9
                  Originally posted by Delerna
                  Yes, that is correct it won't bring back all the values.

                  This is because the numbers 3.1 and 3.10 are exactly same number
                  but the strings 3.1 and 3.10 are very different.
                  As I said in my previous post, I really don't understand the question.
                  Why does it matter that if you enter 3.10 and 3.1 is saved. They are both the same number. You may have a valid reason, I don't know.

                  If you convert the varchar as ck suggests then the zero will be dropped again.
                  If you keep the varchar idea then 3.1 and 3.10 won't match in a search.

                  So at this point you are faced with a decision.
                  All number types will drop zeros from the end of the decimal part. There is nothing you can do about that.
                  So either
                  1) you use decimal type, perhaps decimal(18,4) which means 4 decimal places.
                  With that
                  an entry of 3.1 will appear in queries as 3.1000
                  an entry of 4.190 will appear in queries as 4.1900

                  or

                  2) You use some other number type such as float or real
                  which means an entry of 3.10 will appear in queries as 3.1
                  and an entry of 4.190 will appear in queries as 4.19
                  or

                  3) you use a varchar and come up with some tricky way to keep the number as string but still be able to search correctly.

                  Perhaps you can select the field in your queries twice. Once for displaying the number as entered and the second one you convert it back to a number for your query searching.
                  HI,
                  Thank U for u suggession!!
                  Now I Got!!

                  Comment

                  Working...