title: How to fetch the conversion factor for any unit conversion
body: <p>When you convert between 2 entities, you usually do it via the <a href="http://jscience.org/api/javax/measure/converter/UnitConverter.html" rel="nofollow">UnitConverter</a>. How should I find out what the conversion factor is? For example:</p>
  
  <pre><code>public static final Unit&lt;Length&gt; KILOMETRE = METER.times(1000);
  public static final Unit&lt;Length&gt; CENTIMETRE = METRE.divide(100);
  </code></pre>
  
  <p>I would like to get the conversion factor programmatically from the converter interfaces (i.e. 1000 b/w KILOMETRE and METER or 1/100 in case of CENTIMETER to METRE)</p>
  
  <p>I am not sure how to fetch this information from the UnitConverter interface.</p>
  
  <p><strong>EDIT1</strong></p>
  
  <pre><code>protected double getConvFactor(Unit&lt;Length&gt; from, Unit&lt;Length&gt; to) {
      double factor = -1;
  
      UnitConverter unitConverter = from.getConverterTo(to);
  
      if (unitConverter instanceof MultiplyConverter) {
          MultiplyConverter multiplyConverter = (MultiplyConverter) unitConverter;
          factor = multiplyConverter.getFactor();
      } else if (unitConverter instanceof AddConverter) {
          AddConverter addConverter = (AddConverter) unitConverter;
          factor = addConverter.getOffset();
      } else if (unitConverter instanceof RationalConverter) {
          RationalConverter rationalConverter = (RationalConverter) unitConverter;
          double divisor = rationalConverter.getDivisor().doubleValue();
          double dividend = rationalConverter.getDividend().doubleValue();
          factor = divisor;
      }
  }
  </code></pre>