title: How to keep n decimal places in Java
body: <p>Hi All it might be a trivial question but as for now I could not find any solution.So asking for your help!</p>
  <p>What I am trying to get is a specific encoding table that looks like this:</p>
  <pre><code>0.000
  0.100
  0.200
  </code></pre>
  <p>I need to keep track of zeroes as I will use them to reconstruct a part of an specific array. Original loop that was creating those numbers is:</p>
  <pre><code>for(int k=0;k&lt;m_0;k++){
      for(int l=0;l&lt;m_1;l++){
          for(int a=0;a&lt;a1;a++){
              
              Y[x-1]=0.1*k+0.01*l+0.001*a;
              x++;
              
          }
          
      }
      
  }
  </code></pre>
  <p>Problem! I could not fix zeros after decimal place and rather then getting table described above I am getting following:</p>
  <pre><code>0.0
  0.1
  0.2
  </code></pre>
  <p>As a solution I have tried to use BigDecimal and DecimalFormat but no success. Any suggestions?</p>
  <p><strong>UPD</strong> Few words what I am trying to do. I am encoding specific array to array and back index correspondence. For example <code>0.100</code> will be decomposed into <code>1 and 0 and 0</code> and used as array index labeling like:</p>
  <p><code>Array1[Method(1,0,0,Y(i)][Method(1,0,0,Y(i))]=Array2[1][0][0]</code></p>
  <p>So that I need an output suitable for assigning array index and string will not do the deal.</p>