數(shù)值型貨幣的大寫轉(zhuǎn)換
2024-07-21 02:20:49
供稿:網(wǎng)友
 
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: 在此處添加構(gòu)造函數(shù)邏輯
 //
 }
 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("數(shù)值超界");
 }
 else
 {
 //--- 處理整數(shù)部分-------- 
 
 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;
 
 }
 
 }
 
 //------處理小數(shù)部分-----
 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; 
 }
 }
}