0

I am working with data for the width and height of books. The data is in decimal form, such as 7.563, which I need to display as a fraction: 7 9/16 in.

The denominator can vary and the decimal value isn't always rounded the same. Here is some sample data and the converted values:

6.438     6 7/16 in.
4.625     4 5/8 in.
7.62      7 5/8 in.
11.0      11 in.
5.68      5 11/16 in.
8.688     8 11/16 in.
4.25      4 1/4 in.

I need the denominators to be integers commonly used for inches. For example, .18 would convert to 3/16 rather than something like 9/50 as shown in this answer.

Is there a formula I can use to do this conversion?

cantera
  • 103
  • I would hope and expect that you know that $6.438\neq 6+\frac{7}{16}=6.4375$. The integer part is easy. For the non-integer part, if you are wanting to round to the nearest sixteenth of an inch then try multiplying the fractional part by sixteen, taking the floor function, and then having that displaying that result over sixteen, simplifying if possible. That is, I propose $\lfloor x\rfloor + \lfloor 16{x}\rfloor/16$. For example, $6.438$ gives $6+\lfloor 16\cdot 0.438\rfloor/16 = 6+\lfloor 7.008\rfloor/16=6+\frac{7}{16}$ – JMoravitz Aug 01 '16 at 04:39
  • Multiply the left of the decimal by 16. Round to the nearest digit. Put over 16. Reduce if nescessary. Example:5.348 => .348 x 16 =5.568 => round to 6 => 5 6/16 => 5 3/8. (Although 5 5/16 is also very close.) – fleablood Aug 01 '16 at 04:47
  • Basically you want n.xyz =n m/16. So .xyz = m/16 so .xyz x 16 = m. Roughly. – fleablood Aug 01 '16 at 04:50
  • Thanks for the comments - I think I can use these and the accepted answer to come up with something that works. – cantera Aug 01 '16 at 05:28

1 Answers1

2

When you work in inches, the only common fractions are powers of $2$. The challenge is where to stop. We know $\frac 12=0.50000$ and $\frac {15}{32}=0.46875$ How close do you need to be to $0.50000$ to decide that the true answer is not some larger denominator? This is not a mathematical question. Certainly if I saw $0.499999995$ I would think it was more likely $\frac 12$ than some fraction with a very large denominator. If I saw $0.48$ I wouldn't be sure whether I should round it to $\frac 12$ or $\frac {15}{32}$. It is closer to $\frac {15}{32},$ but $\frac 12$ is so much more common. If your data comes from people with rulers, I would be confident that no measurement is reported to better than $\frac 1{32}$ inch, so I would round to the closest one of those. Your data are all good to within $\pm 0.01$ inch, which will allow you to find the closest thirty-second. Count your blessings.

Ross Millikan
  • 383,099