這篇文章將為大家詳細(xì)講解有關(guān)C#如何實(shí)現(xiàn)金額轉(zhuǎn)換成中文大寫(xiě)金額,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)專(zhuān)業(yè)為企業(yè)提供白堿灘網(wǎng)站建設(shè)、白堿灘做網(wǎng)站、白堿灘網(wǎng)站設(shè)計(jì)、白堿灘網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、白堿灘企業(yè)網(wǎng)站模板建站服務(wù),10多年白堿灘做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
具體內(nèi)容如下
////// 金額轉(zhuǎn)換成中文大寫(xiě)金額 /// /// eg:10.74 ///public static string MoneyToUpper(string LowerMoney) { string functionReturnValue = null; bool IsNegative = false; // 是否是負(fù)數(shù) if (LowerMoney.Trim().Substring(0, 1) == "-") { // 是負(fù)數(shù)則先轉(zhuǎn)為正數(shù) LowerMoney = LowerMoney.Trim().Remove(0, 1); IsNegative = true; } string strLower = null; string strUpart = null; string strUpper = null; int iTemp = 0; // 保留兩位小數(shù) 123.489→123.49 123.4→123.4 LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString(); if (LowerMoney.IndexOf(".") > 0) { if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2) { LowerMoney = LowerMoney + "0"; } } else { LowerMoney = LowerMoney + ".00"; } strLower = LowerMoney; iTemp = 1; strUpper = ""; while (iTemp <= strLower.Length) { switch (strLower.Substring(strLower.Length - iTemp, 1)) { case ".": strUpart = "圓"; break; case "0": strUpart = "零"; break; case "1": strUpart = "壹"; break; case "2": strUpart = "貳"; break; case "3": strUpart = "叁"; break; case "4": strUpart = "肆"; break; case "5": strUpart = "伍"; break; case "6": strUpart = "陸"; break; case "7": strUpart = "柒"; break; case "8": strUpart = "捌"; break; case "9": strUpart = "玖"; break; } switch (iTemp) { case 1: strUpart = strUpart + "分"; break; case 2: strUpart = strUpart + "角"; break; case 3: strUpart = strUpart + ""; break; case 4: strUpart = strUpart + ""; break; case 5: strUpart = strUpart + "拾"; break; case 6: strUpart = strUpart + "佰"; break; case 7: strUpart = strUpart + "仟"; break; case 8: strUpart = strUpart + "萬(wàn)"; break; case 9: strUpart = strUpart + "拾"; break; case 10: strUpart = strUpart + "佰"; break; case 11: strUpart = strUpart + "仟"; break; case 12: strUpart = strUpart + "億"; break; case 13: strUpart = strUpart + "拾"; break; case 14: strUpart = strUpart + "佰"; break; case 15: strUpart = strUpart + "仟"; break; case 16: strUpart = strUpart + "萬(wàn)"; break; default: strUpart = strUpart + ""; break; } strUpper = strUpart + strUpper; iTemp = iTemp + 1; } strUpper = strUpper.Replace("零拾", "零"); strUpper = strUpper.Replace("零佰", "零"); strUpper = strUpper.Replace("零仟", "零"); strUpper = strUpper.Replace("零零零", "零"); strUpper = strUpper.Replace("零零", "零"); strUpper = strUpper.Replace("零角零分", "整"); strUpper = strUpper.Replace("零分", "整"); strUpper = strUpper.Replace("零角", "零"); strUpper = strUpper.Replace("零億零萬(wàn)零圓", "億圓"); strUpper = strUpper.Replace("億零萬(wàn)零圓", "億圓"); strUpper = strUpper.Replace("零億零萬(wàn)", "億"); strUpper = strUpper.Replace("零萬(wàn)零圓", "萬(wàn)圓"); strUpper = strUpper.Replace("零億", "億"); strUpper = strUpper.Replace("零萬(wàn)", "萬(wàn)"); strUpper = strUpper.Replace("零圓", "圓"); strUpper = strUpper.Replace("零零", "零"); // 對(duì)壹圓以下的金額的處理 if (strUpper.Substring(0, 1) == "圓") { strUpper = strUpper.Substring(1, strUpper.Length - 1); } if (strUpper.Substring(0, 1) == "零") { strUpper = strUpper.Substring(1, strUpper.Length - 1); } if (strUpper.Substring(0, 1) == "角") { strUpper = strUpper.Substring(1, strUpper.Length - 1); } if (strUpper.Substring(0, 1) == "分") { strUpper = strUpper.Substring(1, strUpper.Length - 1); } if (strUpper.Substring(0, 1) == "整") { strUpper = "零圓整"; } functionReturnValue = strUpper; if (IsNegative == true) { return "負(fù)" + functionReturnValue; } else { return functionReturnValue; } }
decimal PriceSum = 32957.2654;
調(diào)用 var PriceSumChinese = MoneyToUpper(PriceSum.ToString());
C#是一個(gè)簡(jiǎn)單、通用、面向?qū)ο蟮木幊陶Z(yǔ)言,它由微軟Microsoft開(kāi)發(fā),繼承了C和C++強(qiáng)大功能,并且去掉了一些它們的復(fù)雜特性,C#綜合了VB簡(jiǎn)單的可視化操作和C++的高運(yùn)行效率,以其強(qiáng)大的操作能力、優(yōu)雅的語(yǔ)法風(fēng)格、創(chuàng)新的語(yǔ)言特性和便捷的面向組件編程從而成為.NET開(kāi)發(fā)的首選語(yǔ)言,但它不適用于編寫(xiě)時(shí)間急迫或性能非常高的代碼,因?yàn)镃#缺乏性能極高的應(yīng)用程序所需要的關(guān)鍵功能。
關(guān)于“C#如何實(shí)現(xiàn)金額轉(zhuǎn)換成中文大寫(xiě)金額”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。