将货币转换为大写形式用c语言,C#将输入的数字转换为大写汉字,用于货币,求教!...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

28.cn.com

推荐于 2017.12.16

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:41%    等级:7

已帮助:808人

直接调chang()这个方法就行

string ht1 = chang(Convert.ToDouble(234.45));

public static string chang(double Digital)

{

//将小写金额转换成大写金额

String[] MyScale = { "分", "角", "圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" };

String[] MyBase = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };

String moneyStr = "";

bool isPoint = false;

string moneyDigital = Digital.ToString();

if (moneyDigital.IndexOf(".") != -1)

{

moneyDigital = moneyDigital.Remove(moneyDigital.IndexOf("."), 1);

isPoint = true;

}

for (int i = moneyDigital.Length; i > 0; i--)

{

int MyData = Convert.ToInt16(moneyDigital[moneyDigital.Length - i].ToString());

moneyStr += MyBase[MyData];

if (isPoint == true)

{

moneyStr += MyScale[i - 1];

}

else

{

moneyStr += MyScale[i + 1];

}

}

while (moneyStr.Contains("零零"))

moneyStr = moneyStr.Replace("零零", "零");

moneyStr = moneyStr.Replace("零亿", "亿");

moneyStr = moneyStr.Replace("亿万", "亿");

moneyStr = moneyStr.Replace("零万", "万");

moneyStr = moneyStr.Replace("零仟", "零");

moneyStr = moneyStr.Replace("零佰", "零");

moneyStr = moneyStr.Replace("零拾", "零");

while (moneyStr.Contains("零零"))

moneyStr = moneyStr.Replace("零零", "零");

moneyStr = moneyStr.Replace("零圆", "圆");

moneyStr = moneyStr.Replace("零角", "");

moneyStr = moneyStr.Replace("零分", "");

moneyStr = moneyStr + "整";

return moneyStr;

}

00分享举报

你可能感兴趣的:(将货币转换为大写形式用c语言)