+ Reply to Thread
Results 1 to 11 of 11

Convert inch fractions to decimal, improve formula

  1. #1
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Convert inch fractions to decimal, improve formula

    I have length in inches written in a the common way: 1/4" or 3" or 2 1/4".
    I wish to convert these numbers to decimal.
    I did some lazy googling, both on the www and on this site specifically but nothing life changing popped up.

    I then solved the task myself, the solution looking like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Not the worst formula I have ever produced but certainly not the best either.

    Can this formula be made in a smarter, shorter, better way?

    And how is that CONVERT thing supposed to work? It gives all kinds of numbers.
    Attached Files Attached Files
    <----- If you were helped by my posts you can say "Thank you" by clicking the star symbol down to the left

    If the problem is solved, finish of the thread by clicking SOLVED under Thread Tools
    I don't wish to leave you with no answer, yet I sometimes miss posts. If you feel I forgot you, remind me with a PM or just bump the thread.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,970

    Re: Convert inch fractions to decimal, improve formula

    I don't have a better way to convert from fractional format in text to decimal numeric format without writing it in VBA.

    But you are using CONVERT on strings; it is intended to be used with numeric values. I don't know the complete specification for CONVERT (Microsoft is really bad at giving rigorous specifications) but from your results it appears that:

    CONVERT can successfully convert a text string of a mixed fraction to a numeric value (e.g., 1 1/4). All your integers and mixed fractions (rows 8-14) are converted correctly

    CONVERT cannot successfully convert a string of a proper fraction. However, instead of giving a #VALUE! error, it converts the fraction to a date (e.g., interprets 1/4 as April 4). This gives hilarious results (rows 2-7).
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: Convert inch fractions to decimal, improve formula

    I found this one a long time ago, I can't remember where but I saved it for converting from fractions to decimals...
    =IFERROR(SUBSTITUTE("0 "&A2,"""","")+0,SUBSTITUTE(A2,"""","")+0)
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  4. #4
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Convert inch fractions to decimal, improve formula

    Wow! That was brutally simple!

  5. #5
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: Convert inch fractions to decimal, improve formula

    Wow! That was brutally simple!
    Isn’t it? I wish I could remember where I found it, I give the person who wrote it attribution.

    AND thank you for the rep!

  6. #6
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Convert inch fractions to decimal, improve formula

    Fun fact; I made a column where I removed the " sign and then tried to apply the core of Sam's formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    but that FAILS!
    Presumable because the fraction is in a cell where Excels perverted "turn-anything-into-a-date" -function strikes its claws into it.
    In Sam's formula, the " -less values are just an intermediate result and out of reach of the freaky date thing.

  7. #7
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.96 for Mac MS 365
    Posts
    8,690

    Re: Convert inch fractions to decimal, improve formula

    I used to be an administrator for a product where I would pull data and one of the variables was in ranges and one of the ranges was 10-13 and every time I'd pull that data it would be put out as a CSV file and excel would always convert it to Oct 13 and whatever year we were in. Finally I went into the programming for the application and put ' in front of the range - just that one. That fixed the issue. I could not seem to get around the "freaky date thing" as you put it.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,432

    Re: Convert inch fractions to decimal, improve formula

    I haven't seen this suggested, but I find this is the simplest way to deal with fractional entries in Excel.

    1) KEY STEP. Preformat the data entry cells as fraction (I used # #/#). This will cause Excel to interpret hand entered data as fractional numbers. In your file, I selected I2:I20 and preformatted as fraction. I note that this doesn't work as well for data imported from a text file. You haven't stated where the data are coming from, so I assumed it was hand entered.
    2) With the cells preformatted, I can just enter the fractions as they are in column A -- without the trailing " character.
    3) I can now replicate column B in column J with a simple =I2 formatted as general.
    4) I can replicate column C in column K with a simple =J2*25.4

    If the data are being hand entered, then I would find this straightforward by taking the extra effort before data entry to make sure Excel will enter the numbers correctly at the data entry point.

    Does that help at all?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,970

    Re: Convert inch fractions to decimal, improve formula

    Quote Originally Posted by Sam Capricci View Post
    I found this one a long time ago, I can't remember where but I saved it for converting from fractions to decimals...
    =IFERROR(SUBSTITUTE("0 "&A2,"""","")+0,SUBSTITUTE(A2,"""","")+0)
    This taught me that Excel can convert the string "0 1/8" into 0.125 with forced coercion, but not "1/8". This is consistent with my post on how CONVERT works.

  10. #10
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Convert inch fractions to decimal, improve formula

    Quote Originally Posted by MrShorty View Post
    I haven't seen this suggested, but I find this is the simplest way to deal with fractional entries in Excel.

    ...

    I kind of knew about this, I have played around with it before. I even made a custom list that produces the most common pipe sizes that I could then use for both filling and sorting. A surprisingly nice feature.
    Last edited by AliGW; 10-27-2023 at 02:36 AM. Reason: Please do NOT quote unnecessarily! Use the QUICK REPLY button instead.

  11. #11
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,885

    Re: Convert inch fractions to decimal, improve formula

    Quote Originally Posted by 6StringJazzer View Post
    This taught me that Excel can convert the string "0 1/8" into 0.125 with forced coercion, but not "1/8". This is consistent with my post on how CONVERT works.
    Yeah. I love Excel and all the freedom it gives me but in some cases Excel fails hard for no apparent reason (point in case) which is really annoying.

+ 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. [SOLVED] Converting decimal inch to fractional inch
    By awelton in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 10-25-2022, 09:34 AM
  2. Replies: 12
    Last Post: 02-02-2021, 01:55 AM
  3. [SOLVED] Convert Feet - Inch - Inch Fraction string into numerical value
    By plans in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-25-2017, 11:29 PM
  4. Replies: 9
    Last Post: 12-19-2014, 07:29 PM
  5. Convert 1/2-20 3a fractions into decimal
    By TheNewGuy in forum Excel General
    Replies: 2
    Last Post: 06-24-2009, 10:07 AM
  6. [SOLVED] Decimal to feet/inch/fractional inch conversion
    By Rodney Sergent in forum Excel General
    Replies: 1
    Last Post: 08-10-2006, 10:50 PM
  7. convert decimal to inch & fraction
    By davepatrob in forum Excel General
    Replies: 1
    Last Post: 12-31-2005, 01:10 AM

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