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

首頁 > 開發 > 綜合 > 正文

(C#)數值型貨幣的大寫轉換

2024-07-21 02:18:39
字體:
來源:轉載
供稿:網友
本人現在做的項目要求對數值型貨幣,轉換成大寫,在網上搜索了半天,沒有找到c#寫的類型,不得不自己寫了,測試了,還能滿足要求,只是算法有點繁瑣,有哪位大蝦再給改改!
下面就是我得代碼:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

namespace winmarket
{
/// <summary>
/// classfun 的摘要說明。
/// </summary>
public class classfun
{
private string capstr;

public classfun()
{
//
// todo: 在此處添加構造函數邏輯
//
}
public string moneynumtocap(decimal num)
{
string cap="零壹貳叁肆伍陸柒捌玖";
string numstr="0123456789";
string moneynumstr=num.tostring();
int pint=moneynumstr.indexof(".");
int numint;

string moneyint=null;
string moneydec=null;
string intstr=null;
string moneycap=null;
string moneyintstr=null;
string moneydecstr=null;
// capstr=pint.tostring();

if(pint!=-1)
{
string strarr=".";
char[] chararr=strarr.tochararray();
string[] moneynumarr=moneynumstr.split(chararr);
moneyint=moneynumarr[0].tostring();
moneydec=moneynumarr[1].tostring();

}
else
{
moneyint=moneynumstr;
moneydec="00";
}

if(moneyint.length>16)
{
messagebox.show("數值超界");
}
else
{
//--- 處理整數部分--------

for(int j=1;j<=moneyint.length;j++)
{
moneyintstr=moneyint.substring(j-1,1);
for(int i=0;i<=9;i++)
{

intstr=numstr.substring(i,1);
moneycap=cap.substring(i,1);

if(moneyintstr==intstr)
{

switch (intstr)
{
case "0":
capstr=capstr+moneycap;
break;
case "1":
capstr=capstr+moneycap;
break;
case "2":
capstr=capstr+moneycap;
break;
case "3":
capstr=capstr+moneycap;
break;
case "4":
capstr=capstr+moneycap;
break;
case "5":
capstr=capstr+moneycap;
break;
case "6":
capstr=capstr+moneycap;
break;
case "7":
capstr=capstr+moneycap;
break;
case "8":
capstr=capstr+moneycap;
break;
case "9":
capstr=capstr+moneycap;
break;
}
}
}
numint=moneyint.length-j+1;
switch (numint)
{
case 16:
capstr=capstr+"仟萬";
break;
case 15:
capstr=capstr+"佰萬";
break;
case 14:
capstr=capstr+"拾萬";
break;
case 13:
capstr=capstr+"萬";
break;

case 12:
capstr=capstr+"仟";
break;

case 11:
capstr=capstr+"佰";
break;

case 10:
capstr=capstr+"拾";
break;

case 9:
capstr=capstr+"億";
break;

case 8:
capstr=capstr+"仟";
break;

case 7:
capstr=capstr+"佰";
break;

case 6:
capstr=capstr+"拾";
break;


case 5:
capstr=capstr+"萬";
break;

case 4:
capstr=capstr+"仟";
break;
case 3:
capstr=capstr+"佰";
break;
case 2:
capstr=capstr+"拾";
break;
case 1:
capstr=capstr+"元";
break;

}

}

//------處理小數部分-----
for(int j=1; j<=2; j++)
{
moneydecstr=moneydec.substring(j-1,1);

for(int i=0;i<=9;i++)
{
intstr=numstr.substring(i,1);
moneycap=cap.substring(i,1);
if(moneydecstr==intstr)
{

switch (intstr)
{
case "0":
capstr=capstr+moneycap;
break;
case "1":
capstr=capstr+moneycap;
break;
case "2":
capstr=capstr+moneycap;
break;
case "3":
capstr=capstr+moneycap;
break;
case "4":
capstr=capstr+moneycap;
break;
case "5":
capstr=capstr+moneycap;
break;
case "6":
capstr=capstr+moneycap;
break;
case "7":
capstr=capstr+moneycap;
break;
case "8":
capstr=capstr+moneycap;
break;
case "9":
capstr=capstr+moneycap;
break;
}
}
}


switch(j)
{
case 1:
capstr=capstr+"角";
break;
case 2:
capstr=capstr+"分";
break;

}

}

}

return capstr;
}








}
}




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五华县| 蓬莱市| 赣榆县| 拜城县| 墨玉县| 舒城县| 扶绥县| 阳西县| 无极县| 平和县| 资兴市| 云阳县| 腾冲县| 托里县| 砀山县| 大宁县| 禄丰县| 樟树市| 卢龙县| 阳新县| 昌乐县| 汉阴县| 普陀区| 平南县| 福海县| 绿春县| 龙胜| 沧州市| 介休市| 闻喜县| 乌鲁木齐市| 北流市| 凯里市| 曲水县| 洪泽县| 乐陵市| 柳江县| 平顶山市| 汉寿县| 奉新县| 鸡东县|