{"id":3843,"date":"2023-10-31T19:02:13","date_gmt":"2023-10-31T11:02:13","guid":{"rendered":"https:\/\/white-night.club\/?p=3843"},"modified":"2024-01-29T17:04:19","modified_gmt":"2024-01-29T09:04:19","slug":"pg19","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/31\/pg19\/","title":{"rendered":"C#\uff1a\u534e\u6c0f\u6e29\u5ea6\u8f6c\u4e3a\u6444\u6c0f\u6e29\u5ea6"},"content":{"rendered":"\n<p>\u533a\u522b\u4e8eC++\u548cC\uff0c\u5728C#\u4e2d\u9664\u4e86float\u548cdouble\uff0c\u8fd8\u5f15\u5165\u4e86\u7cbe\u5ea6\u66f4\u9ad8\u7684decimal\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u4ec0\u4e48\u662fdecimal<\/p>\n<cite><em>\u7cbe\u5ea6\u66f4\u9ad8\uff0c\u8303\u56f4\u66f4\u5c0f<\/em><\/cite><\/blockquote>\n\n\n\n<p>C#\u5f15\u5165\u4e86\u65b0\u7684\u6570\u636e\u7c7b\u578bdecimal\u3002\u76f8\u6bd4\u4e8e32\u4f4d\u7684float\u548c64\u4f4d\u7684double\uff0cdecimal\u8868\u793a128\u4f4d\u6570\u636e\u7c7b\u578b\u3002\u4e0d\u8fc7decimal\u867d\u7136\u7cbe\u5ea6\u6bd4double\u66f4\u9ad8\uff0c\u4f46\u8fd9\u662f\u56e0\u4e3adecimal\u53ef\u8868\u793a\u7684\u5c0f\u6570\u4f4d\u8981\u6bd4double\u66f4\u591a\uff0c\u800c\u6574\u6570\u8303\u56f4\u8981\u6bd4double\u5c0f\u3002<\/p>\n\n\n\n<p>\u5728C#\u4e2d\uff0c\u5982\u679c\u6ca1\u6709\u6307\u660e\u662fdecimal\u7c7b\u578b\u7684\u503c\uff0c\u7edf\u4e00\u9ed8\u8ba4\u4e3adouble\u7c7b\u578b\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>decimal\u7c7b\u578b\u7684\u8fd0\u7b97<\/p>\n<cite><em>\u4ee5\u8ba1\u7b97\u6444\u6c0f\u5ea6\u4e3a\u4f8b<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u4e3a\u5565\u8981\u5355\u72ec\u5f00\u7bc7\u6587\u7ae0\u8bb2\u4e0bdecimal\u7c7b\u578b\uff1f\u4e3b\u8981\u662f\u5982\u679c\u4f60\u4e4b\u524d\u662f\u5199C\/C++\u7684\uff0c\u5f88\u5bb9\u6613\u78b0\u5230\u4e00\u4e2a\u5751\u3002\u5b98\u65b9\u7ed9\u7684\u4f8b\u5b50\u5c31\u5f88\u4e0d\u9519\u3002\u76f4\u63a5\u653e\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized has-custom-border\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1cc0203b2b7f2fcfa4dca03bad39d45.png\" alt=\"\" class=\"wp-image-3848\" style=\"border-style:none;border-width:0px;border-radius:0px\" width=\"673\" height=\"512\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1cc0203b2b7f2fcfa4dca03bad39d45.png 897w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1cc0203b2b7f2fcfa4dca03bad39d45-300x228.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/10\/1cc0203b2b7f2fcfa4dca03bad39d45-768x584.png 768w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/figure>\n\n\n\n<p>\u7531\u4e8e\u7cbe\u5ea6\u95ee\u9898\uff0c\u6700\u540e\u8fd4\u56de\u7684temperature\u53ea\u80fd\u662fdecimal\u7c7b\u578b\uff0cdouble\u7c7b\u578b\u7684\u8bdd\u8fbe\u4e0d\u5230\u793a\u4f8b\u8f93\u51fa\u8fd9\u79cd\u7cbe\u5ea6\uff08\u5efa\u8bae\u81ea\u5df1\u8bd5\u4e00\u4e0b\u8f93\u51fadouble\u7c7b\u578b\u7684temperature\uff09\u3002\u800c\u8fd9\u91cc\u6709\u51e0\u79cd\u5e38\u89c1\uff0c\u4f46\u662f\u6709\u5751\u7684\u5199\u6cd5\u3002\u5148\u662f\u8fd9\u79cd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int fahrenheit=94;\ndecimal wa=(fahrenheit-32)*(5\/9);\nConsole.WriteLine($\"The temperature is {wa}\");<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u7ed3\u679c\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The temperature is 0<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u9519\u7684\u5730\u65b9\u5f88\u660e\u663e\u4e86\uff0c\uff085\/9)\u8fd9\u5757\u5730\u65b9\u662f\u4e24\u4e2aint\u6570\u76f8\u9664\uff0c\u540e\u9762\u7684\u5c0f\u6570\u4f4d\u88ab\u622a\u65ad\u4e86\u3002\u6240\u4ee5\u524d\u9762\u5c31\u7b97\u5b9a\u4e49wa\u662fdecimal\u4e5f\u6ca1\u7528\u3002<\/p>\n\n\n\n<p>\u53e6\u4e00\u79cd\u5199\u6cd5\u5728C\/C++\u91cc\u9762\u5f88\u5e38\u89c1\uff0c\u5bf9\u5206\u6570\u4f5c\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int fahrenheit=94;\ndecimal wa=(fahrenheit-32)*(5.0\/9.0);\nConsole.WriteLine($\"The temperature is {wa}\");<\/code><\/pre>\n\n\n\n<p>However\uff0c\u4f60\u4f1a\u5f97\u5230\u4ee5\u4e0b\u62a5\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(2,12): error CS0266: Cannot implicitly convert type 'double' to 'decimal'. An explicit conversion exists (are you missing a cast?)<\/code><\/pre>\n\n\n\n<p>\u2019<em>implicitly convert<\/em>\u2018\uff0c\u5f88\u5e38\u89c1\u5566\uff0c\u8bf4\u7684\u5c31\u662fdouble\u4e0d\u80fd\u9690\u5f0f\u8f6c\u6362\u4e3adecimal\u3002\u800c\u8fd9\u9898\u6211\u4eec\u53c8\u4e0d\u80fd\u76f4\u63a5\u7528double\uff0c\u4e0d\u7136\u7cbe\u5ea6\u4e0d\u591f\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u6307\u660e\u5206\u6570\u76f8\u9664\u4e4b\u540e\u7684\u7ed3\u679c\u5e94\u8be5\u662fdecimal\u7c7b\u578b\u3002\u90a3\u4e48\u6b63\u786e\u7684\u5199\u6cd5\u5e94\u8be5\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int fahrenheit=94;\ndecimal wa=(fahrenheit-32)*(5m\/9);\nConsole.WriteLine($\"The temperature is {wa}\");<\/code><\/pre>\n\n\n\n<p>\u4e5d\u5206\u4e4b\u4e94\u4e0a\u9762\u5e26m\u6216\u8005\u4e0b\u9762\u5e26m\u90fd\u884c\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u5df1\u4f5c\u7c7b\u578b\u8f6c\u6362\u3002\u5f53\u7136\u4e3a\u4e86\u53ef\u8bfb\u6027\u8fd8\u662f\u4e0a\u4e0b\u90fd\u5e26\u6bd4\u8f83\u597d\u3002\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\u4e3a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The temperature is 34.444444444444444444444444447<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u4ec0\u4e48\u662fdecimal\u7c7b\u578b<\/p>\n","protected":false},"author":1,"featured_media":3838,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[97,33],"tags":[137],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3843"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=3843"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3838"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}