LoginSignup
6
6

More than 5 years have passed since last update.

文字列から浮動小数点数値への型変換

Last updated at Posted at 2015-01-05

String -> Int の型変換はすぐに検索できたが、String ->Double の変換を調べるのに苦労したので、記しておく。

var str: String = "10.5"
var num: Double = NSString(String: str).doubleValue //10.5

上記での記述でキャストできた。


ちなみに、
ver str = "10.5"
var num = str.toDouble()
var num = Double(str)
var num = str.doubleValue()
var num = str.toFloat()

上の5つの方法で試したが、全部うまくいかなかった。

6
6
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6