+ Reply to Thread
Results 1 to 13 of 13

Convert Time to Decimal with Custom Time Matrix

  1. #1
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Post Convert Time to Decimal with Custom Time Matrix

    I am working on a formula to convert flight time into tenths of a decimal but with a catch -there is always a catch, isn't there. The client has specific ranges for which to round up:

    :00 - :02 = .0
    :03 - :08 = .1
    :09 - :14 = .2
    :15 - :20 = .3
    :21 - :26 = .4
    :27 - :32 = .5
    :33 - :38 = .6
    :39 - :44 = .7
    :45 - :50 = .8
    :51 - :56 = .9
    :57 - 1.02 =1.0

    When I put my start time in D5 and finish time in D7, I want the total flight time with the above variables to be displayed in E5. I found some formulas that seemed like they were close, but I can't account for the non-standard rounding - the first group it's two min, the rest are 5 min groups.

    Any ideas??
    Last edited by john.fries; 02-03-2016 at 12:02 PM.

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Convert Time to Decimal with Custom Time Matrix

    Looks like you want the results in fractions of an hour ?

    Try
    = MROUND((D7-D5)*24, 0.1)
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

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

    Re: Convert Time to Decimal with Custom Time Matrix

    Can we assume (as ChemistB did) that the numbers are true "time values" and not "text that looks like time"? If they are, it seems to me that even the basic ROUND() function should do this =ROUND((D7-D5)*24,1). There is nothing unusual, as far as I can tell, about the "rounding table" you have listed there.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Convert Time to Decimal with Custom Time Matrix

    Good Point Mister S. :::slaps forehead:::

  5. #5
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Re: Convert Time to Decimal with Custom Time Matrix

    Yes, this worked. I appreciate your response. I don't know why this just looked wrong to me, maybe I just over-thought it.

  6. #6
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Exclamation Re: Convert Time to Decimal with Custom Time Matrix

    OK... so now, another question. I created this document on a MAC and the formula works as advertised. My colleague created the exact same document in Excel 07 on a windows computer and her document counted the tenths after 3 min, not 2, using the exact same formula. Basically one computer used 2 min at the front of the hour and 3 min at the end of the hour, the other used 3 min at the front of the hour and 2 min at the end of the hour. Any explanation for this??

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Convert Time to Decimal with Custom Time Matrix

    I am on a PC and it worked the same as your MAC. Format the cell with time to include Seconds and see if it's different than your data. Maybe

    =ROUND(MROUND(D7-D5, "0:01:00"+0)*24, 0.1)

  8. #8
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Re: Convert Time to Decimal with Custom Time Matrix

    Perfect, that worked on both my document and my colleague's document - it just reversed the output. Still don't know the WHY, but you are a wizard!

  9. #9
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Re: Convert Time to Decimal with Custom Time Matrix

    Hello again, I've been using the formula and everything was good until someone found an anomaly. When I go through the times and check the formula it works as advertised. However, someone found that depending on the start time used, it skews the result by .1 - However, it's not predictable and makes the spreadsheet completely unreliable. To make matters worse, I had to move the spreadsheet to Google Sheets using the same formulas and it has the same problems. I sanitized the spreadsheet and cant figure out how to post it here for review and help.
    Attached Files Attached Files
    Last edited by john.fries; 03-14-2016 at 08:44 AM.

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

    Re: Convert Time to Decimal with Custom Time Matrix

    Edit post dialog should be a "manage attachments" link below the composition window. Click on this link to bring up the upload manager (at least it does for me). I have not had trouble with this site's uploader, but it seems that others do, so hopefully that will work.

    If it helps, what you are describing has echoes of the "penny off" type problems that accountants wrestle with or any of the other ways that "round-off error" inherent in all computer computations manifests itself. So, if you do manage to get a file uploaded, that is the first thing I will look for. Remember that time values in Excel are simply numbers/fractions. Since Excel cannot exactly represent these values, these errors can cause this kind of problem, and I would be checking to see if that is possibly a problem here.

  11. #11
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Re: Convert Time to Decimal with Custom Time Matrix

    I was able to upload the file - see above - for it. What I don't understand is that each of the values are exactly 9 minutes apart or exactly 15 min apart, but the formula converts the decimals to different values. Plus it seems to be very random and I can't produce the same results between Excel and Google Sheets.

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

    Re: Convert Time to Decimal with Custom Time Matrix

    Just as I suspected -- computer round off error.
    What I don't understand is that each of the values are exactly 9 minutes apart or exactly 15 min apart
    What you need to understand is that, to Excel, there is no such thing as times that are "exactly" 9 minutes apart, because 9 minutes (when expressed as a fraction of a day) will a repeating, non-terminating decimal in binary notation. This means that some "9 minutes" are seen by the computer as slightly larger than 9 minutes and some 9 minutes are slightly smaller (illustrated in attachment).

    Solutions to this depend on the individual programmer and the exact nature of the problem. If I understand what you are trying to do here, I would probably simply add a small amount to each difference (1e-8 or 1 ms or something like that) before the round step. Something like MROUND((J3-I3+1e-8)...). This additional fraction will hopefully push anything infinitesimally close to 9 minutes (or other boundary value) over the boundary value so it rounds correctly, but still be small enough so that values well below 9 minutes will still round down.
    Attached Files Attached Files
    Last edited by MrShorty; 03-14-2016 at 11:21 AM.

  13. #13
    Registered User
    Join Date
    02-03-2016
    Location
    Allentown, PA
    MS-Off Ver
    2010 Mac
    Posts
    17

    Re: Convert Time to Decimal with Custom Time Matrix

    ok, I will give it a go. Thanks again

+ 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. Convert time to decimal
    By ExpressTyping in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2013, 11:27 PM
  2. [SOLVED] convert decimal number to time : convert 1,59 (minutes, dec) to m
    By agenda9533 in forum Excel General
    Replies: 22
    Last Post: 09-15-2013, 10:43 AM
  3. [SOLVED] Need to convert time to decimal
    By JessicaW in forum Excel General
    Replies: 2
    Last Post: 10-02-2012, 05:33 PM
  4. Convert decimal to time
    By jonasbirk in forum Excel General
    Replies: 1
    Last Post: 09-07-2011, 01:08 PM
  5. Help me to convert time ti decimal value
    By rickybhai in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 08-29-2011, 08:56 AM
  6. Excel 2007 : Convert decimal to time
    By jbritt in forum Excel General
    Replies: 7
    Last Post: 01-03-2010, 08:10 PM
  7. [SOLVED] Convert Time Decimal to standard time.
    By GTVT06 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-19-2006, 12:30 PM

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