title: Overflow-safe way to calculate percentage from two longs in Java
body: <p>I have two non-negative longs. They may be large, close to Long.MAX_VALUE. I want to calculate a percentage from the two numbers.</p>
  
  <p>Usually I'd do this:</p>
  
  <pre><code>    long numerator = Long.MAX_VALUE / 3 * 2;
      long denominator = Long.MAX_VALUE;
  
      int percentage = (int) (numerator * 100 / denominator);
      System.out.println("percentage = " + percentage);
  </code></pre>
  
  <p>This is not correct if numerator is within two order of magnitudes to Long.MAX_VALUE.</p>
  
  <p>What's a correct, simple, and fast way to do this?</p>