+ Reply to Thread
Results 1 to 5 of 5

Excel precision through queries

  1. #1
    Registered User
    Join Date
    01-21-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Excel precision through queries

    Hello,

    I have a program that uses a query to grab data from overseas. I have an issue where some precision is apparently lost and I was curious if there was a way around this.

    As an example of what is going on I have a specific piece of data I am tracking. The value is 14.9 in the SQL database and it's datatype there is a real of length 4. After grabbing this item from the query I checked the record set and the value is still 14.9. After it reaches the worksheet though it is displayed as 14.89999962. The destination cell is currently formatted as General but I have tried Text as well. Both produce the same results. As this tool is very general I would not have it formatted as a number as I don't know what I am getting back exactly.

    I know computers store real/single values inprecisely but I see it everywhere else as 14.9. I would think Excel would display what I am seeing. Is there anyway around this short of formatting the cell as number with 1 decimal place?

    Thanks in advance.
    Last edited by edpfister; 05-02-2009 at 03:17 PM.

  2. #2
    Registered User
    Join Date
    01-21-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Excel precision through queries

    So has no one seen this or is there just no solution? Any kind of feedback would be nice.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel precision through queries

    I assume the data in the SQL database is single-precision. I say that because 14.89999962 is the closest single-precision representation of 14.9 (hex 416E6666; note the repeating decimal).

    Shown in Excel, you see the double-precision representation of that Single converted to a Double. A Double can't represent 14.9 exactly either (note the repeating decimal CCC..., rounded in last position below), but there's a lot of code space between the two numbers in double precision (see below)

    Please Login or Register  to view this content.
    Last edited by shg; 05-01-2009 at 11:19 AM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    01-21-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Excel precision through queries

    Thanks for the reply, that was very helpful and explains clearly what is going on.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Excel precision through queries

    You’re welcome. Would you please mark the thread as Solved?

    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1