C#中金额大小写的转换
请各位同仁帮忙,帮小第写个金额大小写的转换的方法,用C#
请各位同仁帮忙,帮小第写个金额大小写的转换的方法,用C#
解决方案 »
- winform 打印的代码
- protected static变量冲突
- C# WINFORM 服务器上文件夹的图片如何显示到客户端的控件上面来。
- ArcEngine 打印使用.mxt 模板的问题
- C# 的 String 中,能不能保存不可见字符,比如 0x1c 或 0x1d 等?
- 。NET如何调用WIN32 DLL的变量啊?
- 为什么我用md5加密出来的结果字符串是31位的呢?
- 怎样通过ComboBox获取对应的值?
- C#调用VC++的DLL函数,参数问题
- C#类的使用
- 如何让axWebBrowser控件变成所见即所得的网页编辑模式?
- 请问如何用 Net Remoting传送FileStream类型的参数?
{
public Money(double theMoney)
{
this.m_thedMoney = theMoney;
} public Money(decimal theMoney)
{
//
// TODO: 在此处添加构造函数逻辑
//
this.m_theMoney = theMoney;
} private decimal m_theMoney;
private double m_thedMoney; /// <summary>
/// 获得decimal类型数字的中文大写形势
/// </summary>
/// <param name="m_theMoney">decimal类型数字</param>
/// <returns>返回string类型的数字的中文大写形势</returns>
public string CmycurD()
{
string str1 = "零壹贰叁肆伍陆柒捌玖"; //0-9所对应的汉字
string str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"; //数字位所对应的汉字
string str3 = ""; //从原m_theMoney值中取出的值
string str4 = ""; //数字的字符串形式
string str5 = ""; //人民币大写金额形式
int i; //循环变量
int j; //m_theMoney的值乘以100的字符串长度
string ch1 = ""; //数字的汉语读法
string ch2 = ""; //数字位的汉字读法
int nzero = 0; //用来计算连续的零值是几个
int temp; //从原m_theMoney值中取出的值
m_theMoney = Math.Round(Math.Abs(m_theMoney),2); //将m_theMoney取绝对值并四舍五入取2位小数
str4 = ((long)(m_theMoney*100)).ToString(); //将m_theMoney乘100并转换成字符串形式
j = str4.Length; //找出最高位
if (j > 15){return "溢出";}
str2 = str2.Substring(15-j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分
//循环取出每一位需要转换的值
for(i=0;i<j;i++)
{
str3 = str4.Substring(i,1); //取出需转换的某一位的值
temp = Convert.ToInt32(str3); //转换为数字
if (i != (j-3) && i != (j-7) && i != (j-11) && i != (j-15))
{
//当所取位数不为元、万、亿、万亿上的数字时
if (str3 == "0")
{
ch1 = "";
ch2 = "";
nzero = nzero + 1;
}
else
{
if(str3 != "0" && nzero != 0)
{
ch1 = "零" + str1.Substring(temp*1,1);
ch2 = str2.Substring(i,1);
nzero = 0;
}
else
{
ch1 = str1.Substring(temp*1,1);
ch2 = str2.Substring(i,1);
nzero = 0;
}
}
}
else
{
//该位是万亿,亿,万,元位等关键位
if (str3 != "0" && nzero != 0)
{
ch1 = "零" + str1.Substring(temp*1,1);
ch2 = str2.Substring(i,1);
nzero = 0;
}
else
{
if (str3 != "0" && nzero == 0)
{
ch1 = str1.Substring(temp*1,1);
ch2 = str2.Substring(i,1);
nzero = 0;
}
else
{
if (str3 == "0" && nzero >= 3)
{
ch1 = "";
ch2 = "";
nzero = nzero + 1;
}
else
{
if (j >= 11)
{
ch1 = "";
nzero = nzero + 1;
}
else
{
ch1 = "";
ch2 = str2.Substring(i,1);
nzero = nzero + 1;
}
}
}
}
}
if (i == (j-11) || i == (j-3))
{
//如果该位是亿位或元位,则必须写上
ch2 = str2.Substring(i,1);
}
str5 = str5 + ch1 + ch2;
if (i == j-1 && str3 == "0" )
{
//最后一位(分)为0时,加上“整”
str5 = str5 + '整';
}
}
if (m_theMoney == 0)
{
str5 = "零元整";
}
return str5;
} /// <summary>
/// 根据钱数变换字体颜色
/// </summary>
/// <param name="theMoney">钱数</param>
/// <param name="dotLong">小数后几位</param>
/// <param name="moneyType">InCome或者Expenses</param>
/// <returns></returns>
public string IncomeAndExpensesString(int dotLong,string moneyType)
{
string returnString = String.Empty;
double returnMoney = Math.Abs(this.m_thedMoney);
RegionInfo rTemp = new RegionInfo("CN");
switch(dotLong)
{
case 2:
string theColor = this.GetStringColor(moneyType);
returnString = "<font color='"+theColor+"'>"+returnMoney.ToString(rTemp.CurrencySymbol+"0.00")+"</font>";
break;
default:
returnString = this.m_thedMoney.ToString();
break;
}
return returnString;
} private string GetStringColor(string moneyType)
{
string returnString = String.Empty;
if(this.m_thedMoney<0)
{
returnString = "red";
}
else if(this.m_thedMoney==0)
{
returnString = "black";
}
else if(moneyType=="InCome")
{
returnString = "green";
}
else if(moneyType == "Expenses")
{
returnString = "red";
}
else if(moneyType == String.Empty || moneyType == "Default")
{
if(this.m_thedMoney>0)
{
returnString = "green";
}
else if(this.m_thedMoney==0)
{
returnString = "black";
}
else
{
returnString = "red";
}
}
return returnString;
}
}
http://www.cnblogs.com/esshs/archive/2005/03/30/128318.aspx
RETURNS varchar(100) WITH ENCRYPTION
AS
BEGIN
--版权所有:pbsql
DECLARE @n_data VARCHAR(20),@c_data VARCHAR(100),@n_str VARCHAR(10),@i int SET @n_data=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS varchar(20)),14)
SET @c_data=''
SET @i=1
WHILE @i<=14
BEGIN
SET @n_str=SUBSTRING(@n_data,@i,1)
IF @n_str<>' '
BEGIN
IF not ((SUBSTRING(@n_data,@i,2)='00') or
((@n_str='0') and ((@i=4) or (@i=8) or (@i=12) or (@i=14))))
SET @c_data=@c_data+SUBSTRING('零壹贰叁肆伍陆柒捌玖',CAST(@n_str AS int)+1,1)
IF not ((@n_str='0') and (@i<>4) and (@i<>8) and (@i<>12))
SET @c_data=@c_data+SUBSTRING('仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)
IF SUBSTRING(@c_data,LEN(@c_data)-1,2)='亿万'
SET @c_data=SUBSTRING(@c_data,1,LEN(@c_data)-1)
END
SET @i=@i+1
END
IF @num<0
SET @c_data='(负数)'+@c_data
IF @num=0
SET @c_data='零圆'
IF @n_str='0'
SET @c_data=@c_data+'整'
RETURN(@c_data)
END