Results 1 to 5 of 5
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    159

    Decimal Numbers stored in a table are not accurate.

    I created a table with a field called PercentOfFormula. Datatype is Single (wasn't sure what to use - this could be the problem).



    I'm storing chemical formulas have 10% of this, 20% of that, and even fractions of a percent (ie .35%) of some trace ingredients. Since I needed the decimal to represent these fractions of a percent, I decided to use the aforementioned Single datatype.

    After plugging in all my many ingredients and their percentages (only 2 fields in this easy table), I expected everything to add up to 100% when I did a quick check. This would confirm I entered everything correctly. I ran a Totals query using Sum() on that field since I didn't want to do it by hand. To my surprise, everything adds up to something like "0.999999968800694". This is REALLY weird because I never used more than 4 digits to the right of a decimal.

    My guess is that its something to do with the datatype. I tried the Decimal datatype but it seemed like it only accepted whole numbers for some reason. Maybe I'm doing something wrong. It's been a long time since I've used Access.

    A quick and dirty solution would be appreciated, although, I am willing to do a deep dive into the understanding of datatypes if you think it's prudent that I do so.

    Thank you for any help,
    Matt

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    If you only need 4 decimals,use currency. It has a limit of 4 decimals, just be sure to set the format to remove the $ sign.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    Setting the field properties to:

    Field Size: Decimal
    Format: Fixed
    Decimal Places: 4

    should give the desired result.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,411
    I suggest using Decimal and specify scale and precision properties in the table.Precision is the total number of digits allowed in a number, including left and right of the decimal.
    Scale is the number of digits allowed to the right of the decimal.


    So 1234567.89 has a precision of 9.
    123456.789 has a precision of 9 and a scale of 3.


    A precision of 4 and scale of 2 would result in a number with a maximum value of 99.99


    Percent designations like 125.5% would require precision 4 and scale of 3 (not one) since it is actually stored as 1.255.


    Precision has a maximum value of 28, but textboxes in forms allow only a max of about 15 decimal places.

  5. #5
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    159
    Thank you all for your advice. I appreciate it.
    matt

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importiing large numbers decimal problems
    By Profector in forum Import/Export Data
    Replies: 3
    Last Post: 05-06-2020, 11:25 AM
  2. Replies: 1
    Last Post: 07-20-2017, 02:44 AM
  3. Formatting Numbers in Decimal Places
    By bigmatt911 in forum Queries
    Replies: 3
    Last Post: 12-20-2013, 12:46 PM
  4. Format decimal numbers with fixed width
    By Persist in forum Programming
    Replies: 5
    Last Post: 07-14-2010, 05:43 PM
  5. Non programer needs help in decimal numbers
    By Peter O in forum Access
    Replies: 1
    Last Post: 10-07-2008, 12:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums