{"id":8,"date":"2024-11-06T15:43:46","date_gmt":"2024-11-06T07:43:46","guid":{"rendered":"https:\/\/blog.wuhensama.top\/?p=8"},"modified":"2024-11-06T15:43:46","modified_gmt":"2024-11-06T07:43:46","slug":"c%e9%87%91%e9%a2%9d%e5%a4%a7%e5%86%99%e8%bd%ac%e5%b0%8f%e5%86%99","status":"publish","type":"post","link":"https:\/\/blog.wuhensama.top\/index.php\/2024\/11\/06\/c%e9%87%91%e9%a2%9d%e5%a4%a7%e5%86%99%e8%bd%ac%e5%b0%8f%e5%86%99\/","title":{"rendered":"C#\u91d1\u989d\u5927\u5199\u8f6c\u5c0f\u5199"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/\/\/ &lt;summary&gt;\n\/\/\/ C#\u91d1\u989d\u5927\u5199\u8f6c\u5c0f\u5199\n\/\/\/ &lt;\/summary&gt;\npublic static decimal RMBChineseConvertToNumber(string str)\n{\n    str = str.Replace(\"\u96f6\", \"\").Replace(\"\u6574\", \"\");\n\n    var arr = str.ToCharArray();\n    decimal money = 0;   \/\/\u6700\u7ec8\u7684\u91d1\u989d\n\n    bool yi = false;\n    bool wan = false;\n    bool qian = false;\n    bool bai = false;\n    bool shi = false;\n    bool yuan = false;\n    bool jiao = false;\n    bool fen = false;\n\n    for (int i = (arr.Length - 1); i &gt;= 0; i--)\n    {\n        decimal cur = 0;\n\n        if (arr&#91;i] == '\u5206')\n        {\n            fen = true;\n            continue;\n        }\n        else if (arr&#91;i] == '\u89d2')\n        {\n            jiao = true;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u5143')\n        {\n            yuan = true;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u62fe' || arr&#91;i] == '\u5341')\n        {\n            shi = true;\n            yuan = false;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u4f70' || arr&#91;i] == '\u767e')\n        {\n            bai = true;\n            shi = false;\n            yuan = false;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u4edf' || arr&#91;i] == '\u4efb' || arr&#91;i] == '\u5343')\n        {\n            qian = true;\n            bai = false;\n            shi = false;\n            yuan = false;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u4e07' || arr&#91;i] == '\u842c')\n        {\n            wan = true;\n            qian = false;\n            bai = false;\n            shi = false;\n            yuan = false;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n        else if (arr&#91;i] == '\u4ebf')\n        {\n            yi = true;\n            wan = false;\n            qian = false;\n            bai = false;\n            shi = false;\n            yuan = false;\n            jiao = false;\n            fen = false;\n            continue;\n        }\n\n        if (fen) cur = ConvertNameToSmall(arr&#91;i]) * 0.01M;\n        else if (jiao)\n        {\n            cur = ConvertNameToSmall(arr&#91;i]) * 0.1M;\n            jiao = false;\n        }\n        else if (shi) cur = ConvertNameToSmall(arr&#91;i]) * 10;\n        else if (bai) cur = ConvertNameToSmall(arr&#91;i]) * 100;\n        else if (qian) cur = ConvertNameToSmall(arr&#91;i]) * 1000;\n        else if (yuan) cur = ConvertNameToSmall(arr&#91;i]) * 1;\n        else\n        {\n            cur = ConvertNameToSmall(arr&#91;i]);\n        }\n\n        if (yi)\n        {\n            cur = cur * 100000000;\n        }\n        else if (wan)\n        {\n            cur = cur * 10000;\n        }\n        else\n        {\n            \/\/  cur = cur;\n        }\n\n        money += cur;\n    }\n\n    return money;\n}\n\nprivate static decimal ConvertNameToSmall(char str)\n{\n    decimal name = 0;\n    switch (str.ToString())\n    {\n        case \"\u96f6\": name = 0M; break;\n        case \"\u3007\": name = 0M; break;\n        case \"\u58f9\": name = 1M; break;\n        case \"\u4e00\": name = 1M; break;\n        case \"\u8d30\": name = 2M; break;\n        case \"\u4e8c\": name = 2M; break;\n        case \"\u53c1\": name = 3M; break;\n        case \"\u4e09\": name = 3M; break;\n        case \"\u8086\": name = 4M; break;\n        case \"\u56db\": name = 4M; break;\n        case \"\u4f0d\": name = 5M; break;\n        case \"\u4e94\": name = 5M; break;\n        case \"\u9646\": name = 6M; break;\n        case \"\u516d\": name = 6M; break;\n        case \"\u67d2\": name = 7M; break;\n        case \"\u4e03\": name = 7M; break;\n        case \"\u634c\": name = 8M; break;\n        case \"\u516b\": name = 8M; break;\n        case \"\u7396\": name = 9M; break;\n        case \"\u4e5d\": name = 9M; break;\n        default: break;\n    }\n    return name;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-8","post","type-post","status-publish","format-standard","hentry","category-net","tag-2"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/posts\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":1,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/posts\/8\/revisions\/10"}],"wp:attachment":[{"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wuhensama.top\/index.php\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}