+ Reply to Thread
Results 1 to 7 of 7

Need help understanding Number rouding Excel does

  1. #1
    Registered User
    Join Date
    06-27-2014
    Location
    Hyderabad
    MS-Off Ver
    2010
    Posts
    5

    Need help understanding Number rouding Excel does

    Hi,

    I am writing a program that would dump excel contents into CSV file and have problems with Numbers which Excel (2010) stores in IEEE754 format.

    All numbers are being dumped as shown below

    Data As Appears in Excel:

    1.01 HELLO
    2.11 1/1/2014
    3.21 ONE
    4.31 1/1/2014 12:14
    5.441 $10
    6.241 TWO
    77.11 Zulfi
    8.11 99
    9.11 99.999
    10.11 0

    Data Dumped into text file by my Python code:

    1.01|'HELLO'
    2.1099999999999999|'2014-01-01 00:00:00.000000'
    3.21|'ONE'
    4.3099999999999996|'2014-01-01 12:14:00.000000'
    5.4409999999999998|10.0
    6.2409999999999997|'TWO'
    77.109999999999999|'Zulfi'
    8.1099999999999994|99.0
    9.1099999999999994|99.998999999999995
    10.109999999999999|0.0

    The Python's XLRD module is fetching the IEEE754 data it finds for each cell but what I want is what that appears in the Excel sheet. To understand more of what excel is doing I have played with it and inferred that the Excel cell displays only 9 digits of precision i.e If I enter "4.01234567890123" the cell shows only "4.012345679"

    To understand more, I have pasted the a list of numbers into two excel columns, the first column is formatted as text and the other as General

    Below is the observation:

    6.2400000000|6.24
    6.2412345678|6.241234568
    6.2499999999|6.25
    6.2411111111|6.241111111
    6.2422222222|6.242222222
    6.2433333333|6.243333333
    6.2444444444|6.244444444
    6.2455555555|6.245555556
    6.2466666666|6.246666667
    6.2477777777|6.247777778
    6.2488888888|6.248888889
    6.2499999999|6.25

    I am looking for the formula (or a logic that I can place in my Python Code) that would give me the second row by taking the number from first row.

    Thanks
    Last edited by zulfi123786; 06-27-2014 at 11:31 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Need help understanding Number rouding Excel does

    Quote Originally Posted by zulfi123786 View Post
    I am looking for the formula (or a logic that I can place in my Python Code) that would give me the second row by taking the number from first row.
    Not sure which one is second row and first row

    It will be helpful if you show it in excel


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Need help understanding Number rouding Excel does

    Disclaimer: I have never used the Python programming language.

    That said, shouldn't it be as easy as using Python's ROUND() method? http://www.tutorialspoint.com/python/number_round.htm
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    06-27-2014
    Location
    Hyderabad
    MS-Off Ver
    2010
    Posts
    5

    Re: Need help understanding Number rouding Excel does

    Quote Originally Posted by :) Sixthsense :) View Post
    Not sure which one is second row and first row

    It will be helpful if you show it in excel
    The columns are delimited with '|' pipe character and in the first data list they are delimited with tab character.

  5. #5
    Registered User
    Join Date
    06-27-2014
    Location
    Hyderabad
    MS-Off Ver
    2010
    Posts
    5

    Re: Need help understanding Number rouding Excel does

    Quote Originally Posted by MrShorty View Post
    Disclaimer: I have never used the Python programming language.

    That said, shouldn't it be as easy as using Python's ROUND() method? http://www.tutorialspoint.com/python/number_round.htm
    The rounding is not so straight forward,
    1. When I paste "2.1099999999999999" into excel cell it is displayed as 2.11 and the formula section shows '2.10999999999999' which is 14 digits post decimal
    2. When I paste "6.2409999999999997" into excel cell it is displayed as 6.241 and the formula section shows '6.24099999999999' which is 14 digits post decimal

    The number of significant digits post decimal keeps changing, if that would have been consistent I can use the round function to that number of digits.

    Thanks

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Need help understanding Number rouding Excel does

    I'm not sure I understand the problem still.

    Are you concerned that the displayed value is different from the actual cell value in Excel? This is common in spreadsheets. A cell contains a full double precision value, but displays that value according to the applied number format for that cell. If the cell format is "General", Excel will generally display a number to the number of digits needed to fill the cell up. If the format is "0.000", it will display the value rounded to three digits past the decimal point. An important thing to realize is that number formatting in a spreadsheet does not effect the underlying value -- Excel still stores and uses the cell value to it's full double precision.

    In a spreadsheet, when you need to be sure that the displayed value is exactly the same as the underlying value, you will use Excel's ROUND() function (instead of number formatting) to force the cell value and the displayed value to be the same (http://office.microsoft.com/en-us/ex...455.aspx?CTT=1).

    Is that closer to the concern you are having, or am I still not understanding?

  7. #7
    Registered User
    Join Date
    06-27-2014
    Location
    Hyderabad
    MS-Off Ver
    2010
    Posts
    5

    Re: Need help understanding Number rouding Excel does

    Apologies if my post was un-clear.

    As mentioned in my earlier post, I am designing Python code that would dump the excel contents into CSV file.

    When the values are dumped into CSV, I want to have the values that appears in the cell to be dumped rather than the real values of double precession's which is actually stored.

    Suppose an user types 4.31 in the cell formatted as General, it would get stored as double precision whose real values is '4.3098989898989801' and if '9.3478' is entered it would be stored as '9.3477999999999994'.

    My Python code when run against the above excel containing 4.31 and 9.3478 fetches the below values
    4.3098989898989801
    9.3477999999999994

    The excel files are user created and I don't have any control over them, the users would run this Python code when they want convert them into CSV files (this is on Unix environment)

    From 4.3098989898989801,9.3477999999999994 I have to get back '4.31' and '9.3478' which is exactly what the user entered any other values if fetched would be called as a bug by the user.

    Why Rounding would not help:

    4.31 has two digits of precision
    9.3478 has 4 digits of precision and if rounded to 2 digits of precision it would end up as 9.35 which is not what the user entered.

    Since the users can enter data with varying digits of precision, I can't apply the round function.

    Having said this, If '4.31' is entered and its stored as '4.3098989898989801', if the excel is closed and reopened and it displays '4.31' it means that excel is applying some formula or has remembered the exact precision of the user entered value so it was able to get back 4.31 from 4.3098989898989801 and 9.3478 from 9.3477999999999994

    If I enter 4.3098989898989801 in the excel cell (format as General) it shows me 4.31 instead of 4.3098989898989801 which means it has rounded to two decimal digits and when I enter 9.3477999999999994 it shows 9.3478 and this time it has rounded to 4 digits of precision.

    This means that excel dealing with the inputs 4.3098989898989801,9.3477999999999994 in some fashion to get 4.31 and 9.3478 ? I need to do the same in my Python code to get back what the user actually entered.

    Hope I have made my issue clear.

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. New to Excel and need help understanding Macros
    By jferris266 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2012, 12:41 PM
  2. Incremental Rouding - Multiples of 6
    By DragonballZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2009, 07:27 PM
  3. understanding excel
    By petriti in forum Excel General
    Replies: 1
    Last Post: 12-06-2006, 12:42 PM
  4. Rouding up times. e.g. 7:33 --> 7:35
    By Najeeb in forum Excel General
    Replies: 1
    Last Post: 05-19-2005, 08:06 PM
  5. Rouding Dates to beginning of a week
    By Peter W in forum Excel General
    Replies: 3
    Last Post: 02-15-2005, 08:07 PM

Tags for this Thread

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