GOOGLE SHEETS: Converting fractional text to a number

ddub25

Well-known Member
Joined
Jan 11, 2007
Messages
625
Office Version
  1. 2019
Platform
  1. Windows
The mini sheet example contains text of 1/2 " in C4 and a formula in D4 that is aimed at converting that text into it's correct number value. The result should be 0.5 and not 45323.00, can anyone help with correcting the formula?

Book1
CD
41/2 "45323.00
Sheet1
Cell Formulas
RangeFormula
D4D4=IF(ISBLANK(C4), "", IF(ISNUMBER(VALUE(SUBSTITUTE(SUBSTITUTE(C4, " mm", ""), """", ""))), VALUE(SUBSTITUTE(SUBSTITUTE(C4, " mm", ""), """", "")), IF(ISERROR(FIND(" ", C4)), VALUE(LEFT(C4, FIND("/", C4)-1)) / VALUE(MID(C4, FIND("/", C4)+1, LEN(C4) - FIND("/", C4))), VALUE(LEFT(C4, FIND(" ", C4)-1)) + VALUE(MID(C4, FIND(" ", C4)+1, FIND("/", C4) - FIND(" ", C4)-1)) / VALUE(MID(C4, FIND("/", C4)+1, FIND("""", C4)-FIND("/", C4)-1)) ) ) )
 
Last edited by a moderator:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
There should be a shorter way
Excel Formula:
=LEFT(SUBSTITUTE(A1,CHAR(34),""),SEARCH("/",SUBSTITUTE(A1,CHAR(34),""))-1)/MID(SUBSTITUTE(A1,CHAR(34),""),SEARCH("/",SUBSTITUTE(A1,CHAR(34),""))+1,99)
 
Upvote 0
Perhaps
Book1 (version 2).xlsb
CD
41/2 "0.5
Sheet6
Cell Formulas
RangeFormula
D4D4=LEFT(C4,FIND("/",C4)-1)/MID(SUBSTITUTE(C4,"""",""),FIND("/",C4)+1,99)
 
Upvote 0
Here's one that will work with various measurements:
Logistics Revised.xlsx
CD
41/4 "0.25
51/2 mm0.5
61/8 g0.125
71/3 '0.333333
81/50.2
Sheet2
Cell Formulas
RangeFormula
D4:D8D4=LEFT(C4,FIND("/",C4)-1)/LEFT(RIGHT(C4,LEN(C4)-FIND("/",C4))&" ",FIND(" ",C4&" ")-2)
 
Upvote 0
Upvote 0
Thanks. All of your suggestions solve the problem if C4 = 1/2 “ or other fractions. (Although this suggestions didn't work: =--("0 "&LEFT(C4,IFERROR(FIND(" ",C4)-1,LEN(C4)))))

The reason why my original formula was a bit more complex was because C4’s value will change and may contain a fraction with a whole number like 1 1/2 “, for example, and may also contain just a number with no symbol like, 550 for example. When C4 contains fractions, or whole numbers with fractions, it is formatted as text, but when it contains a number like 550, it is formatted as a number.

My original formula works for all those scenarios, apart from if C4 = 1/2 “ or other fractions. Is it possible to incorporate your formula into the original formula?
 
Upvote 0
(Although this suggestions didn't work: =--("0 "&LEFT(C4,IFERROR(FIND(" ",C4)-1,LEN(C4)))))
Did it only not work because you seem to have picked up an additional ")" ?
As you can see in the XL2BB above and the one below it definitely works on the example format originally provided.
Having a whole number already added does change the requirement though.

Book5
CD
41/2 "0.5
Sheet6
Cell Formulas
RangeFormula
D4D4=--("0 "&LEFT(C4,IFERROR(FIND(" ",C4)-1,LEN(C4))))
 
Upvote 0
I am working in Google Sheets and thought that the syntax between the 2 programs was the same when it came to formulas in the formula bar. I am guessing that is why some suggestions are not working.

@Alex Blakenburg, I entered your formula as: =--("0 "&LEFT(C4,IFERROR(FIND(" ",C4)-1,LEN(C4)))) correctly on this occasion, but it still returned ‘#VALUE!.’ in Excel or Google Sheets when entering a whole number and fraction (1 1/2 “), or a number (560). It works with a fraction (1/2 “) formatted as text.

@FormR, your formula ‘=IF(C4="","",IF(ISNUMBER(C4),C4,0+(IF(FIND(" ",C4&" ")<FIND("/",C4),"","0 ")&(LEFT(C4,FIND(" ",C4&" ",FIND("/",C4))-1)))))’ works for all scenarios in Excel, but not for any fractions, or whole numbers & fractions in Google Sheets. I assume the Plain Text format in Google Sheets upsets things.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top