Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Float or else?

Float or else?

Scheduled Pinned Locked Moved Database
databasetutorialquestion
5 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VisualLive
    wrote on last edited by
    #1

    Hi , i have a doubt to choose a datatype in my database.I have a table with 3 fields : 1 - Code (nvarchar) PK;//in this field there is a code to refer a product. 2 - ProductName (nvarchar); 3 - here i have a doubt ,in this field i need to insert a number (percentage) but i don't know if the best choice is the d float(datatype), the purpose of this field is after the Total of some products we use this percentage to increase the Total for example : if the Total is 25.000 USD i need calculate the Total + 25,7% so 25.000 +25,7%. Which is the better datatype to use in this field to calculate the Total ,is it Float(datatype) or isn't?Can you advice me to apply this step in the right way? Thanks so much for your attention. :)

    M N 2 Replies Last reply
    0
    • V VisualLive

      Hi , i have a doubt to choose a datatype in my database.I have a table with 3 fields : 1 - Code (nvarchar) PK;//in this field there is a code to refer a product. 2 - ProductName (nvarchar); 3 - here i have a doubt ,in this field i need to insert a number (percentage) but i don't know if the best choice is the d float(datatype), the purpose of this field is after the Total of some products we use this percentage to increase the Total for example : if the Total is 25.000 USD i need calculate the Total + 25,7% so 25.000 +25,7%. Which is the better datatype to use in this field to calculate the Total ,is it Float(datatype) or isn't?Can you advice me to apply this step in the right way? Thanks so much for your attention. :)

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Is your data language English, I note you use a comma as a thousand seperator. If Yes then use VARCHAR() instead of nvarchar which supports unicode characters. I use decimal rather than float, there is a slightly larger penalty when using float and IIRC you cannot use a float in an index/constraint.

      Never underestimate the power of human stupidity RAH

      J 1 Reply Last reply
      0
      • M Mycroft Holmes

        Is your data language English, I note you use a comma as a thousand seperator. If Yes then use VARCHAR() instead of nvarchar which supports unicode characters. I use decimal rather than float, there is a slightly larger penalty when using float and IIRC you cannot use a float in an index/constraint.

        Never underestimate the power of human stupidity RAH

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        Mycroft Holmes wrote:

        use VARCHAR() instead of nvarchar which supports unicode characters

        Wrong way round, and whats it got to do with thousand separators?

        M 1 Reply Last reply
        0
        • J J4amieC

          Mycroft Holmes wrote:

          use VARCHAR() instead of nvarchar which supports unicode characters

          Wrong way round, and whats it got to do with thousand separators?

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          nvarchar() supports unicode - I guess the sentence is ambigious. Comma as the thousand seperator indicates non english format, reasonable assumption. All too many people accept the SQL Server default format with no knowledge why it may not be valid.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • V VisualLive

            Hi , i have a doubt to choose a datatype in my database.I have a table with 3 fields : 1 - Code (nvarchar) PK;//in this field there is a code to refer a product. 2 - ProductName (nvarchar); 3 - here i have a doubt ,in this field i need to insert a number (percentage) but i don't know if the best choice is the d float(datatype), the purpose of this field is after the Total of some products we use this percentage to increase the Total for example : if the Total is 25.000 USD i need calculate the Total + 25,7% so 25.000 +25,7%. Which is the better datatype to use in this field to calculate the Total ,is it Float(datatype) or isn't?Can you advice me to apply this step in the right way? Thanks so much for your attention. :)

            N Offline
            N Offline
            Niladri_Biswas
            wrote on last edited by
            #5

            Money Data Type Money is compatible for currency with dollar and cent format. The datatype is accurate to 10 thousand times of the monetary unit. If the field is capable enough to store large aggregates rather than just the largest value, it is recommended to go with Money data type. Also with money, you have the choice to use thousand of separators. Float/Decimal Data Type Float/Decimal is more flexible, not specific to currency. Suppose you have to support 10 numbers and 2 decimals. In this context decimal is a better choice. Also, decimal is more precise( since we can set precision) and scale to numbers. From the above explanations, I think you should go with money data type. :)

            Niladri Biswas

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups