{"id":480,"date":"2021-09-17T15:22:52","date_gmt":"1970-01-01T00:00:00","guid":{"rendered":"http:\/\/swift.tecc0.com\/?p=480"},"modified":"2021-09-17T15:22:52","modified_gmt":"1970-01-01T00:00:00","slug":"post-480","status":"publish","type":"post","link":"https:\/\/swift.tecc0.com\/?p=480","title":{"rendered":"Swift\u3067\u5c0f\u6570(Float, Double)\u3067\u306e\u6d6e\u52d5\u5c0f\u6570\u70b9\u8aa4\u5dee\u3092\u89e3\u6c7a\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Swift\u306b\u9650\u3063\u305f\u3053\u3068\u3067\u306f\u306a\u3044\u304c\u3001<strong>\u5c0f\u6570(Float, Double)<\/strong>\u306e\u8a08\u7b97\u3067\u306f\u3068\u3066\u3082\u7d30\u304b\u3044<strong>\u8aa4\u5dee<\/strong>\u304c\u3067\u308b\u3002<\/p>\n<p>\u3053\u308c\u306e\u7406\u7531\u306fSwift\u306b\u9650\u3063\u305f\u3053\u3068\u3067\u306f\u306a\u3044\u306e\u3067\u5272\u611b\u3059\u308b\u304c\u3001\u6c17\u306b\u306a\u308b\u4eba\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u306a\u3069\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u304b\u3068\u601d\u3046\u3002<\/p>\n<p><a href=\"https:\/\/www.cc.kyoto-su.ac.jp\/~yamada\/programming\/float.html#error\" target=\"_blank\">\u6d6e\u52d5\u5c0f\u6570\u70b9\u6570\u306e\u8aa4\u5dee<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Swift\u3067\u5c0f\u6570(Float, Double)\u3067\u306e\u6d6e\u52d5\u5c0f\u6570\u70b9\u8aa4\u5dee\u304c\u51fa\u308b\u8a08\u7b97<\/h3>\n<pre class=\"lang:swift decode:true\">let d1: Double = 3.14\r\nlet d2: Double = 3.13\r\nprint(d1 - d2) \/\/ 0.0100000000000002\r\n\r\nlet f1: Float = 3.14\r\nlet f2: Float = 3.13\r\nprint(f1 - f2) \/\/ 0.00999999<\/pre>\n<p>\u51fa\u529b\u7d50\u679c\u3092\u898b\u308c\u3070\u308f\u304b\u308b\u3088\u3046\u306b\u8aa4\u5dee\u304c\u751f\u3058\u3001\u601d\u3044\u901a\u308a\u306e\u8a08\u7b97\u7d50\u679c\u306b\u306a\u3089\u306a\u3044\u3002<\/p>\n<p>\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u306b\u306f\u00a0<strong>NSDecimalNumber<\/strong> \u3092\u4f7f\u3048\u3070\u826f\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>Swift\u3067\u5c0f\u6570\u306e\u8aa4\u5dee\u3092\u306a\u304f\u3059\u305f\u3081\u306bNSDecimalNumber\u3092\u4f7f\u3046<\/h3>\n<pre class=\"lang:swift decode:true \">let n1 = NSDecimalNumber(string: \"3.14\")\r\nlet n2 = NSDecimalNumber(string: \"3.13\")\r\nprint(n1.subtracting(n2)) \/\/ 0.01<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u53b3\u5bc6\u306a\u8a08\u7b97\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001NSDecimalNumber\u3092\u4f7f\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u3053\u3046\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swift\u306b\u9650\u3063\u305f\u3053\u3068\u3067\u306f\u306a\u3044\u304c\u3001\u5c0f\u6570(Float, Double)\u306e\u8a08\u7b97\u3067\u306f\u3068\u3066\u3082\u7d30\u304b\u3044\u8aa4\u5dee\u304c\u3067\u308b\u3002 \u3053\u308c\u306e\u7406\u7531\u306fSwift\u306b\u9650\u3063\u305f\u3053\u3068\u3067\u306f\u306a\u3044\u306e\u3067\u5272\u611b\u3059\u308b\u304c\u3001\u6c17\u306b\u306a\u308b\u4eba\u306f\u4ee5\u4e0b\u306e\u8a18\u4e8b\u306a\u3069\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u304b\u3068\u601d\u3046\u3002 \u6d6e\u52d5\u5c0f&#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\/480"}],"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=480"}],"version-history":[{"count":3,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts\/480\/revisions"}],"predecessor-version":[{"id":713,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=\/wp\/v2\/posts\/480\/revisions\/713"}],"wp:attachment":[{"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swift.tecc0.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}