金额大写
,金额额入 框 //inIdID
,大额出 写框 //outIdID
,保存大的文本 写框//txtIdID
,最大位;不含小, 几数数//max
使用方法,//
this.Txt_Amount.Attributes["onkeyup"]="TypeAmount('Txt_Amount','L_Amount','Txt_AmountL
ab',10)"
function TypeAmount(inId,outId,txtId,max) {
var obj = document.getElementById(inId);
document.getElementById(outId).innerHTML = MoneyFormat(obj.value,max);
document.getElementById(txtId).value = document.getElementById(outId).innerHTML;
}
大人民额额额写以分额额位 function MoneyFormat(aiMoney,aiMaxOut){ //()
if (!aiMaxOut){aiMaxOut = 7;}
aiMoney = aiMoney.replace(/,/g,'') ;
lcMoney = parseFloat(aiMoney)+"";
if (lcMoney=='NaN'){lcMoney='0.00'}
if (lcMoney.indexOf('.')==-1){
lcMoney=lcMoney+".00"
}else{
lcMoney=lcMoney.substring(0,lcMoney.indexOf('.')+3)
if (((lcMoney.substring(lcMoney.indexOf('.'))).length)==2){lcMoney=lcMoney+'0'}
}
lcMoneyNs = lcMoney;
lcMoney = lcMoney.replace('.','')
lcMoney = lcMoney.replace('-','')
var liLength=lcMoney.length , lcFormat="";
for (i=1; i<=(aiMaxOut-liLength); i++){
lcMoney = '0' + lcMoney;
}
金额额超出范额 if (liLength>aiMaxOut){lcFormat = '!';aiMaxOut=0;}
liLength=aiMaxOut;
零壹额额肆伍额柒捌玖 var AlterlcMoney= new Array("","","","","","","","","","");
for (i=1; i<=liLength; i++){
var liTempMoney = parseFloat(lcMoney.substring(liLength-i));
lcMoney = lcMoney.substring(0,liLength-i);
分 if (i==1){lcFormat =" " + lcFormat;}
角 if (i==2){lcFormat =" " + lcFormat;}
元 if (i==3){lcFormat =" " + lcFormat;}
拾if (i==4){lcFormat =" " + lcFormat;}
佰 if (i==5){lcFormat =" " + lcFormat;}
仟if (i==6){lcFormat =" " + lcFormat;}
万 if (i==7){lcFormat =" " + lcFormat;}
拾if (i==8){lcFormat =" " + lcFormat;}
佰if (i==9){lcFormat =" " + lcFormat;}
仟 if (i==10){lcFormat =" "+ lcFormat;}
额 if (i==11){lcFormat =" " + lcFormat;}
拾 if (i==12){lcFormat =" " + lcFormat;}
佰 if (i==13){lcFormat =" " + lcFormat;}
仟 if (i==14){lcFormat =" " + lcFormat;}
万 if (i==15){lcFormat =" " + lcFormat;}
lcFormat = "
"+AlterlcMoney[liTempMoney]+"" +
lcFormat;
}
lcMoney = lcFormat;
整 return lcMoney +" ";
}
以下是 方法 /********************* C# *********************/
///
格式化字额出~小额成额额大 数写写///
///
数字 ///
需要的额度///
public static string FormatNumberLab(string num, int len)
{
金额超出范额 if (len > 15) { return ""; }
string rtn = "";
零壹额额肆伍额柒捌玖string[] lc = { "", "", "", "", "", "", "", "", "", "" };
分角元拾佰仟万拾佰仟额拾佰仟string[] lc2 = { "", "", "", "", "", "", "", "", "", "", "", "", "", "",万 "" };
先额成位的字数数//2
num = ValidateNumber(num) ? num : "0.00";
移除小点 数num = (decimal.Parse(num) * 100).ToString("0");//
string lcFormat = "";
向前额额 ~加上小点位数两数num = FormatNumberAhead(num, len+1, "0");//0
for (int i = 0; i <= len; i++)
{
rtn = lcFormat + rtn;
lcFormat = "
" + lc[int.Parse(num[num.Length - i
-1].ToString())] + "";
lcFormat += " " + lc2[i] + " ";
}
整 rtn += " ";
return rtn;
}
///
格式化字额出~向前额额指定字符 数///
///
数字///
需要的额度 ///
指定字符 ///
public static string FormatNumberAhead(string num, int len, string s)
{
string rtn = "";
if (num.Length >= len) { return num; }
ArrayList arr = ArrayList.Repeat(s, len - num.Length);
rtn = string.Join("", arr.ToArray(typeof(string)) as string[]) + num;
return rtn;
}
///
额额文本是否额字数///
///
///
public static bool ValidateNumber(string str)
{
System.Text.RegularExpressions.Regex rex = new
System.Text.RegularExpressions.Regex(@"^(\d+)?(\.(\d+))?$");
return rex.IsMatch(str);
}