title: Display first n digits of a number in Java
body: <p>I am having difficulty of creating a method to display first n digits of a number when 'n' is determined by the user. </p>
  
  <p>For example, user inputs an integer '1234567' and a number of digits to display '3'. The method then outputs '123'. </p>
  
  <p>I have an idea how to display the first digit: </p>
  
  <pre><code>long number = 52345678;
  long prefix = number /= (int) (Math.pow(10.0, Math.floor(Math.log10(number))));
  </code></pre>
  
  <p>But I seem not being able to figure out how to display a user defined first n digits.</p>
  
  <p>Thank you!</p>