title: Convert to fraction inches
body: <p>I need to convert a double value (centimeters) to a fraction value with this format: 3 1/64 (inches). After reading a lot about this and finding algorithms for converting into fractions, I think they are not good for what I need, because my fractions should be in these formats: ?/2, ?/4, ?/8, ?/16, ?/32, ?/64. I have seen conversion tables like this: <a href="https://mdmetric.com/tech/cvtchtfdm.htm" rel="nofollow">table</a>. And I think my best solution is to create a key, value list with all values in the table and for each number find the best approximation in the list.</p>
  
  <p>For example: 3.21 cm. = 1.26378 in = 1 in + 0.26378. So, according the table linked, 0.26378 = 17/64. And the final result should be 1 17/64 inches.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li><p>Is a good idea to have a list with the values in the table and find the closest value in order to give the fraction or it is better to create an algorithm for this?</p></li>
  <li><p>In case it is fine to create a list with the values, how can I find the closest value of a given number in my list?</p></li>
  </ol>