title: Double value with specific precision in java
body: <p>I'm programming a simple java program. I need to get a string from input and divide it into two parts: 1-double 2-string.
  Then I need to do a simple calculation on the double and send the result to the output with specific precision(4). It works fine, but there is a problem when the input is 0, then it doesn't work properly.</p>
  
  <p>For example for these input, output will be:</p>
  
  <p>1 kg<br>
  output:2.2046</p>
  
  <p>3.1 kg<br>
  output:6.8343</p>
  
  <p>But when the input is 0, the output should be 0.0000, but it shows 0.0 .
  What should I do to force it to show 0.0000?</p>
  
  <p>I read similar post about double precision, they suggest something like <code>BigDecimal</code> class, but I can't use them in this case,
  my code for doing this is:</p>
  
  <pre><code>line=input.nextLine();
  array=line.split(" ");
  value=Double.parseDouble(array[0]);
  type=array[1];
  value =value*2.2046;
  String s = String.format("%.4f", value);
  value = Double.parseDouble(s);
  System.out.print(value+" kg\n");
  </code></pre>