{"id":883,"date":"2021-09-19T13:02:10","date_gmt":"2021-09-19T04:02:10","guid":{"rendered":"https:\/\/swift.tecc0.com\/?p=883"},"modified":"2021-09-19T13:04:22","modified_gmt":"2021-09-19T04:04:22","slug":"post-883","status":"publish","type":"post","link":"https:\/\/swift.tecc0.com\/?p=883","title":{"rendered":"Swift\u3067Int, Float, Double\u306e\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8)\u3092\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Int, Float, Double\u306e\u6570\u5024\u3069\u304a\u3057\u306e\u578b\u5909\u63db\u3001\u30ad\u30e3\u30b9\u30c8\u3092\u8aac\u660e\u3057\u3066\u304f\u3088\u3002<\/p>\n<h3>Int to Float\/Double\u306e\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8)<\/h3>\n<pre class=\"lang:swift decode:true\">let age1 = 13 \/\/ Int\r\nlet ageFloat1 = Float(age1)\r\nlet ageDouble1 = Double(age1)\r\n\/\/ \u88dc\u8db3: type(Of: )\u306f\u578b\u3092\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\r\ntype(of: ageFloat1) \/\/ Float.Type\r\ntype(of: ageDouble1) \/\/ Double.Type<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306bFloat(), Double\u306e\u4e2d\u306b\u5024\u3092\u5165\u308c\u308b\u3060\u3051\u3002<\/p>\n<h3>Float to Int\/Double\u306e\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8)<\/h3>\n<pre class=\"lang:swift decode:true \">let age2: Float = 13.0 \/\/ Float\r\nlet ageInt2 = Int(age2)\r\nlet ageDouble2 = Double(age2)\r\n\r\ntype(of: ageInt2) \/\/ Int.Type\r\ntype(of: ageDouble2) \/\/ Double.Type<\/pre>\n<p>\u3053\u3061\u3089\u3082\u4e0a\u8a18\u3068\u540c\u3058\u304f\u3001Int(), Double\u306e\u4e2d\u306b\u5024\u3092\u5165\u308c\u308b\u3060\u3051\u3002<\/p>\n<h3>Double to Int\/Float\u306e\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8)<\/h3>\n<pre class=\"lang:swift decode:true\">let age3: Double = 13.0 \/\/ Double\r\nlet ageInt3 = Int(age3)\r\nlet ageDouble3 = Float(age3)\r\n\r\ntype(of: ageInt2) \/\/ Int.Type\r\ntype(of: ageDouble2) \/\/ Double.Type<\/pre>\n<p>\u3053\u3061\u3089\u3082\u540c\u3058\u3067\u3059\u3002<\/p>\n<h3>\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8)\u306e\u6ce8\u610f\u4e8b\u9805<\/h3>\n<pre class=\"lang:swift decode:true \">let hoge = 3.14 \/\/ 3.14\r\nlet fuga = Int(hoge) \/\/ 3\r\nlet moe = Float(fuga) \/\/ 3<\/pre>\n<p>\u3053\u3061\u3089\u306e\u3088\u3046\u306b\u6700\u521d\u306f3.14\u3068\u3044\u3046\u5024\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u306b\u3001\u4e00\u5ea6Int\u306b\u7a81\u3063\u8fbc\u3093\u3067\u3057\u307e\u3046\u3068Int\u306f\u6574\u6570\u306a\u306e\u3067\u3001\u3082\u3046\u4e00\u5ea6<span style=\"text-decoration: underline;\">Float\u306b\u30ad\u30e3\u30b9\u30c8\u3057\u3066\u623b\u3057\u3066\u3082\u3001\u5c0f\u6570\u70b9\u4ee5\u4e0b\u304c\u6b20\u843d<\/span>\u3057\u3066\u3057\u307e\u3046\u3002<\/p>\n<p>\u3053\u308c\u3092<strong>\u6841\u843d\u3061<\/strong>\u3068\u3044\u3044\u3001\u3053\u308c\u306b\u3088\u308b\u8aa4\u5dee\u3092<strong>\u4e38\u3081\u8aa4\u5dee<\/strong>\u3068\u3044\u3046\u3002<\/p>\n<h3>tips: extension\u3092\u4f7f\u3063\u305f\u66f8\u304d\u65b9<\/h3>\n<p>\u3082\u3063\u3068\u6d41\u308c\u308b\u3088\u3046\u306b\u30ad\u30e3\u30b9\u30c8\u3092\u66f8\u304d\u305f\u3044\u3068\u3044\u3046\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306bextension\u306b\u8ffd\u52a0\u3057\u3066\u3057\u307e\u3046\u3068\u826f\u3044\u3002(\u4eca\u56de\u306f<strong>Int -&gt; float, Dlouble<\/strong>\u306e\u5834\u5408)<\/p>\n<pre class=\"lang:swift decode:true \">let age4 = 13\r\nlet ageFloat4 = age4.toFloat()\r\nlet ageDouble4 = age4.toDouble()\r\n\r\ntype(of: ageFloat4) \/\/ Float.Type\r\ntype(of: ageDouble4) \/\/ Double.Type\r\n\r\nextension Int {\r\n    func toFloat() -&gt; Float {\r\n        Float(self)\r\n    }\r\n    \r\n    func toDouble() -&gt; Double {\r\n        Double(self)\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Int, Float, Double\u306e\u6570\u5024\u3069\u304a\u3057\u306e\u578b\u5909\u63db\u3001\u30ad\u30e3\u30b9\u30c8\u3092\u8aac\u660e\u3057\u3066\u304f\u3088\u3002 Int to Float\/Double\u306e\u578b\u5909\u63db(\u30ad\u30e3\u30b9\u30c8) let age1 = 13 \/\/ Int let ageFloat1 = F&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts\/883"}],"collection":[{"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=883"}],"version-history":[{"count":4,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":887,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts\/883\/revisions\/887"}],"wp:attachment":[{"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}