Common Fractions
that were decimals

Developer Tools | www.onegasoft.com

View PDF ( 42k)
Get zipped PDF ( 32k)

Common fractions from their decimal representation

It seems that most software doesn't like simple fractions and always prefer numbers in decimal form. Of course, it could be very convenient for computers, but we, mere mortals, have, er... problems trying to understand what part of an inch would be 0.4375. It definitely doesn't look so nice as 7/16 which it is.

Fortunately, some of us and me too are developers, so we can do our own fraction displaying routine. It will be a very simple routine. It won't display any decimal number as a fraction, only halves, quarters and so on up to 1/32 (or to any 1/n where n=2x), but it will be simple and easy to understand and modify.

If all possible fractions were halves, it would be rather easy to construct the formula. So the main problem is to understand what fraction we're looking at. Let's, for instance, look at 0.5625. Can you tell off-hand which denominator is hidden here?

It can be answered mathematically, but the process is a bit complex to be kept in a FileMaker calculation field. But there's a much simpler method. It's very easy to discover it just by looking at decimal representation of 1/2, 1/4, 1/8, 1/16 and 1/32:

1/2=0.5, 1/4=0.25, 1/8=0.125, 1/16=0.0625, 1/32=0.03125.

You can see that each fraction has different number of decimal digits: 1, 2, 3, 4 and 5. This is the key to quick and easy conversion. Our number 0.5625 has 4 decimal digits so its denominator is 16. To find the numerator we should multiply the decimal part to 16.

FileMaker doesn't have a special function to get the decimal part of a number, but it can be easily constructed from the Mod() function: Mod(Number, 1).

Now let's get the denominator:

Choose(Length(Mod(Number, 1))-2, 2,4,8,16,32 )

and numerator:

Mod(Number, 1) * Choose(Length(Mod(Number, 1))-2, 2,4,8,16,32)

We only need to glue it together. The final formula also performs some checks. The first Case() statement checks if the number has an integral part and if it does, displays it; the second does the same with the decimal part.

Case(Int(Number), Int(Number) & " " ) & 
Case(
  Mod(Number, 1),
  Mod(Number, 1) * 
      Choose(Length(Mod(Number, 1))-2, 2,4,8,16,32) & "/" & 
      Choose(Length(Mod(Number, 1))-2, 2,4,8,16,32)
  )

View PDF ( 42k) | Get zipped PDF ( 32k)



Everything for FileMaker CD vol. 5 is now available!

Copyright © 2000-2004
Mikhail Edoshin

If you have problems viewing this site, please drop a note to the Link to an e-mail address webmaster