title: How to convert decimal to fractions?
body: <p>What I need to convert decimal to fractions. It is easy to convert to 10's feet.</p>
  
  <pre><code>1.5 =&gt; 15/10
  </code></pre>
  
  <p>This can do via this code:</p>
  
  <pre><code>public class Rational {
  
      private int num, denom;
  
      public Rational(double d) {
          String s = String.valueOf(d);
          int digitsDec = s.length() - 1 - s.indexOf('.');
          int denom = 1;
          for (int i = 0; i &lt; digitsDec; i++) {
              d *= 10;    
              denom *= 10;
          }
  
          int num = (int) Math.round(d);
          this.num = num;
          this.denom = denom;
      }
  
      public Rational(int num, int denom) {
          this.num = num;
          this.denom = denom;
      }
  
      public String toString() {
          return String.valueOf(num) + "/" + String.valueOf(denom);
      }
  
      public static void main(String[] args) {
          System.out.println(new Rational(1.5));
      }
  }
  </code></pre>
  
  <p>But what I want is</p>
  
  <pre><code>1.5 =&gt; 3/2
  </code></pre>
  
  <p>and I don't get how to proceed.
  My question is not a duplication. Because other related question is C#. This is java. </p>