.net 金额中文大写 日期转中文

金额中文大写

        #region 中文大写
/// <summary>
/// 返回中文数字 ,如壹佰元整
/// </summary>
/// <param name="valIn"></param>
/// <param name="strType">0返回金额写法,1返回数量写法</param>
/// <returns></returns>
public static string GetChineseNum(decimal valIn, int strType = )
{ string m_1, m_2, m_3, m_4, m_5, m_6, m_7, m_8, m_9; string numNum = "0123456789.";
string numChina = "零壹贰叁肆伍陆柒捌玖点";
string numChinaWeigh = "个拾佰仟万拾佰仟亿拾佰仟万"; //m_1.Format("%.2f", atof(m_1));
m_1 = valIn.ToString("f2");
m_2 = m_1;
m_3 = m_4 = "";
//m_2:1234-> 壹贰叁肆
for (int i = ; i < ; i++)
{
//m_2=m_2.Replace(numNum.Mid(i, 1), numChina.Mid(i * 2, 2));
m_2 = m_2.Replace(numNum.Substring(i, ), numChina.Substring(i, ));
} //m_3:佰拾万仟佰拾个
int iLen = m_1.Length;
if (iLen > )
{
m_8 = m_9 = "越界错!";
throw new Exception("数字太大,超出处理范围");
}
if (m_1.IndexOf('.') > )
iLen = m_1.IndexOf('.'); for (int j = iLen; j >= ; j--)
{
m_3 += numChinaWeigh.Substring(j - , );
}
//m_4:2行+3行 for (int i = ; i < m_3.Length; i++)
{
m_4 += m_2.Substring(i, ) + m_3.Substring(i, );
}
//m_5:4行去"0"后拾佰仟 m_5 = m_4;
m_5 = m_5.Replace("零拾", "零");
m_5 = m_5.Replace("零佰", "零");
m_5 = m_5.Replace("零仟", "零");
//m_6:00-> 0,000-> 0 m_6 = m_5;
for (int i = ; i < iLen; i++)
m_6 = m_6.Replace("零零", "零"); //m_7:6行去亿,万,个位"0"
m_7 = m_6;
m_7 = m_7.Replace("亿零万零", "亿零");
m_7 = m_7.Replace("亿零万", "亿零");
m_7 = m_7.Replace("零亿", "亿");
m_7 = m_7.Replace("零万", "万");
if (m_7.Length > )
m_7 = m_7.Replace("零个", "个"); //m_8:7行+2行小数-> 数目
m_8 = m_7;
m_8 = m_8.Replace("个", "");
if (m_2.Substring(m_2.Length - , ) != "点零零")
m_8 += m_2.Substring(m_2.Length - , ); //m_9:7行+2行小数-> 价格
m_9 = m_7;
m_9 = m_9.Replace("个", "元");
if (m_2.Substring(m_2.Length - , ) != "点零零")
{
m_9 += m_2.Substring(m_2.Length - , );
m_9 = m_9.Insert(m_9.Length - , "角");
m_9 += "分";
}
else m_9 += "整";
if (m_9 != "零元整")
m_9 = m_9.Replace("零元", "");
m_9 = m_9.Replace("零分", "整");
if (strType == ) //数量
return m_8;
else
return m_9; }
#endregion

日期转中文

        #region 日期转中文

        /// <summary>
/// 日期转中文
/// </summary>
/// <param name="strDate">日期</param>
/// <returns></returns>
public static string GetChineseDate(string strDate)
{
char[] strChinese = new char[] {
'〇','一','二','三','四','五','六','七','八','九','十'
};
StringBuilder result = new StringBuilder(); //// 依据正则表达式判断参数是否正确
//Regex theReg = new Regex(@"(d{2}|d{4})(/|-)(d{1,2})(/|-)(d{1,2})"); if (!string.IsNullOrEmpty(strDate))
{
// 将数字日期的年月日存到字符数组str中
string[] str = null;
if (strDate.Contains("-"))
{
str = strDate.Split('-');
}
else if (strDate.Contains("/"))
{
str = strDate.Split('/');
}
// str[0]中为年,将其各个字符转换为相应的汉字
for (int i = ; i < str[].Length; i++)
{
result.Append(strChinese[int.Parse(str[][i].ToString())]);
}
result.Append("年"); // 转换月
int month = int.Parse(str[]);
int MN1 = month / ;
int MN2 = month % ; if (MN1 > )
{
result.Append(strChinese[MN1]);
}
if (MN1 > )
{
result.Append(strChinese[]);
}
if (MN2 != )
{
result.Append(strChinese[MN2]);
}
result.Append("月"); // 转换日
int day = int.Parse(str[]);
int DN1 = day / ;
int DN2 = day % ; if (DN1 > )
{
result.Append(strChinese[DN1]);
}
if (DN1 > )
{
result.Append(strChinese[]);
}
if (DN2 != )
{
result.Append(strChinese[DN2]);
}
result.Append("日");
}
else
{
throw new ArgumentException();
} return result.ToString();
} #endregion
上一篇:js金额转换大写


下一篇:iOS TableView如何刷新指定的cell或section