ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fraction to decimal (https://www.excelbanter.com/excel-programming/441769-fraction-decimal.html)

Alvin

Fraction to decimal
 
I have a cell with a value of {0'-3/4}
I want another cell to call that value and change the format to
{0'-0 3/4"}

the following code will change it to a decimal when it is formatted correctly:
which is what I am after.

{=SUBSTITUTE(LEFT(H69,FIND("-",H69)-1),"'","")*12+SUBSTITUTE(REPLACE(H69,1,FIND("-",H69),""),"""","")}

Thanks in advance
Alvin Smith

joel[_909_]

Fraction to decimal
 

You can add the text function to format the cell


{=Text(SUBSTITUTE(LEFT(H69,FIND("-",H69)-1),"'","")*12+SUBSTITUTE(REPLACE(H69,1,FIND("-",H69),""),"""",""),ANYFORMAT)}


the format would be in double quotes Like "General" or "0.00"


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=196484

http://www.thecodecage.com/forumz


Joe User[_2_]

Fraction to decimal
 
"Alvin" wrote:
I have a cell with a value of {0'-3/4}
I want another cell to call that value and change
the format to {0'-0 3/4"}
[so] the following code will change it to a decimal
when it is formatted correctly: which is what I am after.


If you would prefer, replace your original formula with the following, which
handles all text of the form 1'-3/4", 1'-2 3/4" and 1'2":

=12*LEFT(A1,FIND(CHAR(39),A1)-1) +
(IF(ISNUMBER(FIND("/",A1)),
IF(ISNUMBER(FIND(" ",A1)),"","0 "), "") &
SUBSTITUTE(MID(A1,1+FIND("-",A1),99),CHAR(34),""))

You can replace CHAR(39) with "'" and CHAR(34) with """". I chose to use
CHAR because the string forms are difficult to read in some fonts.

Note: That is __not__ an array formula. Enter by simply pressing Enter,
not ctrl+shift+Enter. You put curly braces around the formula in your
original posting. I suspect that is your own meta-syntax to quote the
formula. But Excel uses curly braces in that way to denote an array formula.
So your intention is unclear.


----- original message -----

"Alvin" wrote:
I have a cell with a value of {0'-3/4}
I want another cell to call that value and change the format to
{0'-0 3/4"}

the following code will change it to a decimal when it is formatted correctly:
which is what I am after.

{=SUBSTITUTE(LEFT(H69,FIND("-",H69)-1),"'","")*12+SUBSTITUTE(REPLACE(H69,1,FIND("-",H69),""),"""","")}

Thanks in advance
Alvin Smith



All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com