title: Convert decimal amount to text string fraction in Javascript?
body: <p>I have a value returned as a number, with could be decimal number e.g. "1.15".</p>
  
  <p>However, I need to format all numbers <strong>in a range</strong> to a given fraction.  For example, all numbers greater than 0 but less than .2 I want to return "1/8".</p>
  
  <p>I already started to do this as a series of if/else statements, but I was wondering if there was a smarter and neater way.</p>
  
  <pre><code>if (amt &gt; 0 &amp;&amp; amt &lt;= .2){
      q = '1/8';
  } else if (amt &gt; .2 &amp;&amp; amt &lt;= .3){
      q = '1/4';
  }  else if (amt &gt; .3 &amp;&amp; amt &lt;= .4){
      q = '1/3';
  }  else if (amt &gt; .4 &amp;&amp; amt &lt;= .5){
      q = '1/2';
  } else if (amt &gt; .5 &amp;&amp; amt &lt;= .7){
      q = '2/3';
  } else if (amt &gt; .7 &amp;&amp; amt &lt;= .8){
      q = '3/4';
  } else if (amt &gt; .8 &amp;&amp; amt &lt;= 1.0){
      q = '7/8';
  } else if (amt &gt; 1 &amp;&amp; amt &lt;= 1.1){
      q = '1';
  } etc.....
  </code></pre>