title: Java: Better way to convert Double object to float
body: <p>Suppose I'm given a Double object d and a function that takes in a primitive float, is there a better way to pass on object do to the function than by double casting?</p>
  
  <pre><code>Double fakePi = 3.14  
  void function(float num) {}
  </code></pre>
  
  <p><code>function(fakePi)</code>: Returns a compiling error as function does not take Double object as argument </p>
  
  <p><code>function((float) fakePi)</code>: Returns a compiling error as Double cannot be converted to a float</p>
  
  <p><code>function((float) (double) fakePi)</code>: 
  Compiles and runs without error </p>
  
  <p>Although this works, my instincts tells me that there are better ways to do this and that I should avoid doing multiple type castings, especially since float, double, Double are closely related to each other. </p>