+ Reply to Thread
Results 1 to 10 of 10

How to change a formatted fraction into a decimal?

  1. #1
    Registered User
    Join Date
    05-04-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    How to change a formatted fraction into a decimal?

    I have a bunch of data that is like this:
    1/16X001
    1/4X02
    etc

    So I wrote a formula that extracts the fraction leaving me with "1/16" or "1/4"
    I need to also show it as a decimal so I was going to just format it as a number in a different cell.
    I did =A4 (the cell showing only the fraction) but formatting doesn't apply to it. (I presume because its a formula or text)
    So I tried using the NumberValue() or Value() functions but it just converts it oddly.
    NumberValue(A4) or Value(A4)
    Will result in 44942 (if A4 = 1/16).
    Which I can't make heads or tails of.

    How can I convert this to a decimal properly or make it not a formula so I can just use formatting to convert it?

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,950

    Re: How to change a formatted fraction into a decimal?

    Welcome to the forum.

    1/16 is being read by Excel as a date, hence the date serial number.

    There are instructions at the top of the page explaining how to attach your sample workbook. Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    05-04-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Re: How to change a formatted fraction into a decimal?

    I thought that might be the case so I tried changing the formatting to a number.
    I attached an example sheet. I think the problem arises from the fact that I am using a formula to extract the fraction from a string.
    I will also have to do a similar thing with MM->Decimal but 1 thing at a time.
    Example.xlsx

    P.S. Thanks for the welcome!

  4. #4
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: How to change a formatted fraction into a decimal?

    =iferror(--(left(c1,find("/",c1)-1))/--(mid(c1,find("/",c1)+1,find("x",c1)-find("/",c1)-1)),"")

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

    Re: How to change a formatted fraction into a decimal?

    1/16 is being read by Excel as a date, hence the date serial number.
    I know that Excel has a built in preference for interpreting this as a date over a fraction, but I have long wished that this was better controlled by the user. Maybe someday someone designing a spreadsheet will decide that the choice to see fractions before dates ought to be available to us. Until then, we have to work with what we have.

    Knowing that spreadsheets so strongly prefer to see dates before fractions, the only solutions I see involve extracting the numerator and the denominator from the text string, perform the division, and store the result. I see text based solutions using "/" and "X" as delimiters to get the numerator and denominator, then divide. Personally, I prefer Google Sheets SPLIT() function for this (MSFT is developing a similar function for Excel that is currently behind a subscription wall). =SPLIT(A1,"X/") will divide the text into three cells. Then divide the first by the second. =INDEX(SPLIT(A1,"X/"),1)/INDEX(SPLIT(A1,"X/"),2). Apply any number formatting you desire ("#/##" to see the fraction, 0.00% to see it as a percent or whatever you like).

    That's probably how I would do this. Granted, it isn't quite compatible with Excel, but there are equivalent approaches in Excel using Excel's built in text manipulation functions to get the same effect. (windknife's solution, for example).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    05-04-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Re: How to change a formatted fraction into a decimal?

    Quote Originally Posted by windknife View Post
    =iferror(--(left(c1,find("/",c1)-1))/--(mid(c1,find("/",c1)+1,find("x",c1)-find("/",c1)-1)),"")
    This worked! Had to change the x to uppercase though. Can someone explain to me what the -- is for? I understand the iferror.
    Also why find instead of search?


    @MrShorty


    Yea I suppose I will have to do this. Does Google Sheets see fractions before decimals?

    I am also curious to hear more about this Split function. How does Split(A1,"X/") split into 3? By looking at the function I would imagine it searches A1 for "X/" and splits it into 2 parts. Before "X/" and after "X/"....Though typing this out made me realize that the "X/" has to go somewhere which would explain the 3rd. Am I correct?
    Index I assume treats the expression like an array and lets you select a specific item?
    Last edited by AliGW; 05-04-2023 at 11:28 AM. Reason: Please do NOT quote unnecessarily!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,950

    Re: How to change a formatted fraction into a decimal?

    Is this in fact a Google Sheets query?

  8. #8
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: How to change a formatted fraction into a decimal?

    -- convert text to a number.
    You can use search function instead of find function.

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

    Re: How to change a formatted fraction into a decimal?

    Everything I know about Google Sheets SPLIT() function I learned here: https://support.google.com/docs/answer/3094136 Note that the behavior you claim to expect (use the entire X/ string as the delimiter) is the behavior you would get if you put FALSE in the optional "split by each" (third) argument. In my example, I omitted the third (and fourth) argument, so it defaults to TRUE which causes Sheets to split the string at each character within the delimiter string. In the A1 case, the output of the SPLIT() function will be 1,16,010. Then, as you note, you can use the INDEX() function to return one element from that array.

    As far as my limited experience with Sheets, Google also chooses to see dates before fractions. I'm not aware of a spreadsheet that has an option for preferentially seeing fractions before dates. Maybe someday...

    For reference (if/when you gain access to it), here's MSFT's/Excel's TEXTSPLIT() function, which isn't exactly the same as Sheet's SPLIT() function, but is substantially similar: https://support.microsoft.com/en-us/...7-bdecace8a6e7
    Last edited by MrShorty; 05-04-2023 at 11:50 AM.

  10. #10
    Registered User
    Join Date
    05-04-2023
    Location
    USA
    MS-Off Ver
    2016
    Posts
    4

    Re: How to change a formatted fraction into a decimal?

    Quote Originally Posted by AliGW View Post
    Is this in fact a Google Sheets query?
    No, Just curious! I sometimes use sheets at home and I like to learn everything I can!

    Quote Originally Posted by windknife View Post
    -- convert text to a number.
    You can use search function instead of find function.
    Ahhhh Interesting. Are there others like this? I only know of the function CONVERT() but shorthand quick ones(or whatever their name is if they have one) would be useful to know.
    After Googling it, SEARCH() is case-insensitive, while FIND() is case-sensitive.

    Quote Originally Posted by MrShorty View Post
    Everything I know about Google Sheets SPLIT() function I learned here: ------------------------------ Note that the behavior you claim to expect (use the entire X/ string as the delimiter) is the behavior you would get if you put FALSE in the optional "split by each" (third) argument. In my example, I omitted the third (and fourth) argument, so it defaults to TRUE which causes Sheets to split the string at each character within the delimiter string. In the A1 case, the output of the SPLIT() function will be 1,16,010. Then, as you note, you can use the INDEX() function to return one element from that array.

    As far as my limited experience with Sheets, Google also chooses to see dates before fractions. I'm not aware of a spreadsheet that has an option for preferentially seeing fractions before dates. Maybe someday...

    For reference (if/when you gain access to it), here's MSFT's/Excel's TEXTSPLIT() function, which isn't exactly the same as Sheet's SPLIT() function, but is substantially similar:
    Interesting, thank you for the link(that I am not allowed to even quote until I post a few times) and information!
    Thanks to all of you for your assistance and knowledge! : )

+ 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 & fraction
    By Statz in forum Excel General
    Replies: 4
    Last Post: 05-20-2020, 03:42 PM
  2. Decimal fraction
    By gfell153 in forum Excel General
    Replies: 12
    Last Post: 01-29-2018, 07:51 AM
  3. decimal to fraction
    By itselflearn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2015, 11:04 AM
  4. [SOLVED] Fraction to Decimal
    By Michael D in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-13-2013, 03:21 PM
  5. How to display decimal as fraction and mm
    By STU22 in forum Excel General
    Replies: 1
    Last Post: 12-31-2012, 02:34 PM
  6. Convert Text-Formatted Fraction (4 / 4) to Percent %?
    By WilyTrader in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-02-2010, 02:39 PM
  7. How do I change a text fraction. eg 1 1/2 into a decimal number, .
    By antac in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2005, 01:06 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