国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

將人民幣的數字表示轉化成大寫表示(C#版)

2024-07-21 02:19:26
字體:
來源:轉載
供稿:網友
將人民幣的數字表示轉化成大寫表示(c#版)




實在沒有什么好講的,就是一個方法,大家拿去用吧

using system;

namespace test.com
{
/// <summary>
/// 功能:字符串處理函數集
/// </summary>
public class dealstring
{
#region 私有成員
/// <summary>
/// 輸入字符串
/// </summary>
private string inputstring=null;
/// <summary>
/// 輸出字符串
/// </summary>
private string outstring=null;
/// <summary>
/// 提示信息
/// </summary>
private string notemessage=null;
#endregion

#region 公共屬性
/// <summary>
/// 輸入字符串
/// </summary>
public string inputstring
{
get{return inputstring;}
set{inputstring=value;}
}
/// <summary>
/// 輸出字符串
/// </summary>
public string outstring
{
get{return outstring;}
set{outstring=value;}
}
/// <summary>
/// 提示信息
/// </summary>
public string notemessage
{
get{return notemessage;}
set{notemessage=value;}
}
#endregion

#region 構造函數
public dealstring()
{
//
// todo: 在此處添加構造函數邏輯
//
}
#endregion

#region 公共方法
public void converttochinesenum()
{
string numlist="零壹貳叁肆伍陸柒捌玖";
string rmblist = "分角元拾佰仟萬拾佰仟億拾佰仟萬";
double number=0;
string tempoutstring=null;

try
{
number=double.parse(this.inputstring);
}
catch
{
this.notemessage="傳入參數非數字!";
return;
}

if(number>9999999999999.99)
this.notemessage="超出范圍的人民幣值";

//將小數轉化為整數字符串
string tempnumberstring=convert.toint64(number*100).tostring();
int tempnmberlength=tempnumberstring.length;
int i=0;
while(i<tempnmberlength)
{
int onenumber=int32.parse(tempnumberstring.substring(i,1));
string onenumberchar=numlist.substring(onenumber,1);
string onenumberunit=rmblist.substring(tempnmberlength-i-1,1);
if(onenumberchar!="零")
tempoutstring+=onenumberchar+onenumberunit;
else
{
if(onenumberunit=="億"||onenumberunit=="萬"||onenumberunit=="元"||onenumberunit=="零")
{
while (tempoutstring.endswith("零"))
{
tempoutstring=tempoutstring.substring(0,tempoutstring.length-1);
}

}
if(onenumberunit=="億"||(onenumberunit=="萬"&&!tempoutstring.endswith("億"))||onenumberunit=="元")
{
tempoutstring+=onenumberunit;
}
else
{
bool tempend=tempoutstring.endswith("億");
bool zeroend=tempoutstring.endswith("零");
if(tempoutstring.length>1)
{
bool zerostart=tempoutstring.substring(tempoutstring.length-2,2).startswith("零");
if(!zeroend&&(zerostart||!tempend))
tempoutstring+=onenumberchar;
}
else
{
if(!zeroend&&!tempend)
tempoutstring+=onenumberchar;
}
}
}
i+=1;
}

while (tempoutstring.endswith("零"))
{
tempoutstring=tempoutstring.substring(0,tempoutstring.length-1);
}

while(tempoutstring.endswith("元"))
{
tempoutstring=tempoutstring+"整";
}

this.outstring=tempoutstring;


}
#endregion
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富蕴县| 东乡| 博爱县| 格尔木市| 广德县| 全南县| 铜川市| 子洲县| 仙居县| 深圳市| 富蕴县| 石嘴山市| 潮州市| 宁乡县| 六盘水市| 汤阴县| 巨鹿县| 安仁县| 杨浦区| 德安县| 阿拉善盟| 武平县| 呼图壁县| 大城县| 满洲里市| 调兵山市| 丰都县| 鄄城县| 巫溪县| 襄城县| 海阳市| 米易县| 平潭县| 五家渠市| 元阳县| 渝中区| 宁城县| 遂溪县| 绥德县| 昌宁县| 沂水县|