title: Formula px to dp, dp to px android
body: <p>I am trying to calculate a variable amount of pixels to density independent pixels and vice-versa. </p>
  
  <p>This formula <code>(px to dp): dp = (int)(px / (displayMetrics.densityDpi / 160));</code> does not work on small devices because it is divided by zero. </p>
  
  <p>This is my dp to px formula: </p>
  
  <pre><code>px = (int)(dp * (displayMetrics.densityDpi / 160));
  </code></pre>
  
  <p>Could someone give me some pointers?</p>