title: Fastest way to obtain a power of 10
body: <p>I'll use Java as an example here, as it may be completely language-specific, but I'm generally interested in ways to do this.<br>
  Of course, the simplest and obvious way is this:</p>
  
  <pre><code>Math.pow(10, x)
  </code></pre>
  
  <p>but as far as I know, power is a fairly expensive operation. Thus I thought that there should be a better way, because it seems so obvious - I just need x zeroes after the 1!</p>
  
  <p><strong>Edit:</strong>
  Yes, this may be premature optimisation. The context is a rounding operation to n decimal places, which often uses something like this:</p>
  
  <pre><code>private final static int[] powersOf10 = {1, 10, 100, 1000, 10000};
  public static double round(double number, int decimals) {
      if(decimals &lt; 5)
          return Math.rint(number / powersOf10[decimals]) * powersOf10[decimals];
      double c = Math.pow(10, decimals);
      return Math.rint(number * c) / c;
  }
  </code></pre>
  
  <p>This is the current rounding function I use, as you can see I already use a lookup table for the most used values, but I'm still curious whether there's some bit-magic or the like to improve this.</p>