Brian Dunning's FileMaker Custom Functions

FractionToDecimal ( fraction )

Convert fraction string to decimal

  Average rating: 4.8 (28 votes) Log in to vote

Brett Buchmiller   Brett Buchmiller
None
www.filemaker.com

Share on Facebook Share on Twitter

  Sample input:
FractionToDecimal( "1/4" )

FractionToDecimal( "2 69/95" )
  Sample output:
0.25

2.72631579

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Converts a fraction string to a numeric decimal equivalent. Part of a library of functions. Needed additional functions are mentioned in the header comments

 

Comments

L. Allen Poole   L. Allen Poole, Creative Database Solutions NW
Dec 4, 2013
This function appears to fail on integer inputs.
FractionType ( 12 ) returns "Invalid," so FractionToDecimal ( 12 ) returns [null].
Rather than test for integer inputs every time I use this function, I modified it to return integer inputs unmodified.
 
Guy Elsmore-Paddock   Guy Elsmore-Paddock, Inveniem
Jul 12, 2019
Note that this will not work with whole numbers, or numbers that are already decimals.
 
Guy Elsmore-Paddock   Guy Elsmore-Paddock, Inveniem
Jul 12, 2019
Here's a modified version that works for whole numbers (might work with decimals too):
/*
Convert valid fraction to decimal equivalent

From:
https://www.briandunning.com/cf/1360

Require Functions
FractionType
FractionNumerator
FractionDenominator

© Brett Buchmiller 10-2010
Portions © Inveniem 2019 (Whole Number Handling)
*/

Let([
fractionType = FractionType(input)
];

Case(
/* When: A whole number */
fractionType = "Whole";
input;

/* When: Any other type of valid fraction */
fractionType ≠ "Invalid";
FractionNumerator(input) / FractionDenominator(input)
)
)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: