title: Round Double to 1 decimal place kotlin: from 0.044999 to 0.1
body: <p>I have a Double variable that is <code>0.0449999</code> and I would like to round it to 1 decimal place <code>0.1</code> .</p>
  
  <p>I am using Kotlin but the Java solution is also helpful.</p>
  
  <p><code>val number:Double = 0.0449999</code></p>
  
  <p>I tried getting 1 decimal place with these two solutions:</p>
  
  <ol>
  <li><code>val solution = Math.round(number * 10.0) / 10.0</code></li>
  <li><code>val solution = String.format("%.1f", number)</code></li>
  </ol>
  
  <p>The problem is that I get 0.0 in both cases because it rounds the number from <code>0.04</code> to <code>0.0</code>. It doesn't take all decimals and round it.</p>
  
  <p>I would like to obtain 0.1: <code>0.045 -&gt; 0.05 -&gt; 0.1</code></p>