「Swift」文字列のString型からDouble型への変換のサンプル

2021年1月21日

書式
atof(文字列)
Double(文字列)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import Foundation
// atof()メソッド
let cftB:String = "678.231"
let resB:Double = atof(cftB)
print("atof() 結果2:")
print(resB)
// Double()メソッド
let cftA:String = "654.123"
let resA:Double = Double(cftA)!
print("Double() 結果1")
print(resA)
import Foundation // atof()メソッド let cftB:String = "678.231" let resB:Double = atof(cftB) print("atof() 結果2:") print(resB) // Double()メソッド let cftA:String = "654.123" let resA:Double = Double(cftA)! print("Double() 結果1") print(resA)
import Foundation

// atof()メソッド
let cftB:String = "678.231"
let resB:Double = atof(cftB)
print("atof() 結果2:")
print(resB)   

// Double()メソッド
let cftA:String = "654.123"
let resA:Double = Double(cftA)!
print("Double() 結果1")
print(resA)

実行結果
atof() 結果2:
678.231
Double() 結果1
654.123

Swift

Posted by arkgame