Convert fraction to decimal number issue
I need help on modifying this great custom function (see below) found on Brian Dunning's website.
I want to be able to make it work when a fraction is entered as 1-1/2 to give me a decimal number of 1.5. Right now with the custom function it gives me a value of 5.5. The "-" is culprit that causes the issue but I can't figure out how to modify it. I tried a substitute but I still can't get it to work.
Let ( [
$number = Trim(number);
$integer = LeftWords($number;1);
$denominator = Right ( $number ; Length($number)-Position($number; "/";1;1 ));
$numerator = Middle ( $number ; Position ( $number ; " "; 1 ; 1 ) ; Position ( $number ; "/"; 1 ; 1 )-Position ( $number ; " "; 1 ; 1 ) )
// no slash, so no fraction
// no space, so no valid fraction
// too many spaces, so no valid fraction
// - we have a fraction to parse
$integer + ($numerator/$denominator)
Sam Barnum, 360Works
November 16, 2010 11:48am