title: Scala generic cast from String function
body: <p>How can I write a function to convert a String to a generic type (Double, Int, Float, etc.)?</p>
  
  <p>Here's pseudocode for the functionality I'm looking for:</p>
  
  <pre><code>def castFromString[A: Manifest](value: String): A = {
    if (A == Double) {
      parseDouble(value)
    } else if (A == Int) {
      parseInt(value)
    } else {
      value.toString()
    }
  }
  </code></pre>