Significant Figures/Digits.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • draft
    New Member
    • Aug 2008
    • 4

    Significant Figures/Digits.

    Hi All!

    Have a question that I cant get my head around the problem of storing significant digits with a value.


    In C# you can define:
    decimal d = 1.10M

    When you print it and or use it, the 1.10 is stored in side. And not rounded like double (gives 1.1 ).

    But storing the litle bastard is more tricky.

    Storing as:
    nvarchar(11) gives 1.10.
    decimal(8,3) gives 1.100 as well as numeric().


    So is there a nice way to store it in a proper way (Which is type safe.)??

    Regards
    Daniel
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Not quite sure what you are geting at. Your examples show the data being stored as specified. What are you trying to do?
    Just to avoid confusion do you mean significant figures or precision?

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Or use ROUND.

      If it's a question of display, handle it on your front-end.

      -- CK

      Comment

      • draft
        New Member
        • Aug 2008
        • 4

        #4
        Both valid points.

        But there is a difference between 1.10 and 1.100.

        So if the user inputs that for ex. 5.1% should be copper in a chemical composition.

        That means that it can range from 5.05% to 5.14%
        But if he puts 5.10% then the range is 5.095% to 5.104%

        This is needed for calculations. And can be done without a prob. But storing them as entered.. is different thing. Cant store them as decimal because it adds zeros to the end...



        /D

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          So the problem is you wish the data to be stored exactly as entered, without the database engine strippiing or adding trailing zeroes.
          Unfortunateley, with all the numeric data types the significant figures are specified at the creation of the field.
          My immediate thought is converting the data to a string and using a TEXT or VARCHAR field.
          I think these preserve the data exactly as entered. So long as the calculations program casts them correctly.

          Comment

          • draft
            New Member
            • Aug 2008
            • 4

            #6
            Originally posted by code green
            So the problem is you wish the data to be stored exactly as entered, without the database engine strippiing or adding trailing zeroes.
            Unfortunateley, with all the numeric data types the significant figures are specified at the creation of the field.
            My immediate thought is converting the data to a string and using a TEXT or VARCHAR field.
            I think these preserve the data exactly as entered. So long as the calculations program casts them correctly.
            Right on the spot here :)

            I have tested every combination that is possible (almost not the stupid). And for now I have to use the varchar() to store the exact number.

            A bit addtional coding but.. Small price to pay. I can hope that SQL2008 has some proper number storing stereotype.

            Thanks for your time.
            /D

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              Well done.
              Be careful to specify a VARCHAR width slightly bigger than the maximum number of digits expected
              ie 0.000234 is 3 significant figures but with a precision of 6 decimal places and 8 chars in total

              Comment

              Working...