function convertCurrency(currencyDigits,moneyType){
var MAXIMUM_NUMBER = 99999999999.99;
var CN_ZERO = "%u96F6";
var CN_ONE = "%u58F9";
var CN_TWO = "%u8D30";
var CN_THREE = "%u53C1";
var CN_FOUR = "%u8086";
var CN_FIVE = "%u4F0D";
var CN_SIX = "%u9646";
var CN_SEVEN = "%u67D2";
var CN_EIGHT = "%u634C";
var CN_NINE = "%u7396";
var CN_TEN = "%u62FE";
var CN_HUNDRED = "%u4F70";
var CN_THOUSAND = "%u4EDF";
var CN_TEN_THOUSAND = "%u4E07";
var CN_HUNDRED_MILLION = "%u4EBF";
var CN_SYMBOL="";
var CN_DOLLAR = "%u5143";
var CN_TEN_CENT = "%u89D2";
var CN_CENT = "%u5206";
var CN_INTEGER = "%u6574";
var integral; // Represent integral part of digit number.
var decimal; // Represent decimal part of digit number.
var outputCharacters; // The output result.
var parts;
var digits, radices, bigRadices, decimals;
var zeroCount;
var i, p, d;
var quotient, modulus;
//var CN_SYMBOL = moneyType;
if (moneyType!="请选择一项" && moneyType!=""){
CN_SYMBOL = moneyType
}else{
CN_SYMBOL = ""
}
// Validate input string:
currencyDigits = currencyDigits.toString();
if (currencyDigits == ""){
return "";
}
/*
if (currencyDigits.match(/[^,.\d]/) != null)
{
alert("错误:不能包含特殊字符!");
return "";
}
if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null)
{
alert("错误:不是纯数字!");
return "";
}
*/
currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
if (Number(currencyDigits) > MAXIMUM_NUMBER) {
alert("金额不能超过最大值:99999999999.99");
return "";
}
var isNegative=false;
if(currencyDigits.substring(0,1)=="-")
{
isNegative=true;
currencyDigits=currencyDigits.substring(1,currencyDigits.lenght)
}
parts = currencyDigits.split(".");
if (parts.length > 1){
integral = parts[0];
decimal = parts[1];
// Cut down redundant decimal digits that are after the second.
decimal = decimal.substr(0, 2);
}else{
integral = parts[0];
decimal = "";
}
// Prepare the characters corresponding to the digits:
digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
decimals = new Array(CN_TEN_CENT, CN_CENT);
// Start processing:
outputCharacters = "";
// Process integral part if it is larger than 0:
if (Number(integral) > 0) {
zeroCount = 0;
for (i = 0; i < integral.length; i++) {
p = integral.length - i - 1;
d = integral.substr(i, 1);
quotient = p / 4;
modulus = p % 4;
if (d == "0"){
zeroCount++;
}else{
if (zeroCount > 0){
outputCharacters += digits[0];
}
zeroCount = 0;
outputCharacters += digits[Number(d)] + radices[modulus];
}
if (modulus == 0 && zeroCount < 4) {
outputCharacters += bigRadices[quotient];
}
}
outputCharacters += CN_DOLLAR;
}
// Process decimal part if there is:
if (decimal != "") {
for (i = 0; i < decimal.length; i++){
d = decimal.substr(i, 1);
if (d != "0") {
outputCharacters += digits[Number(d)] + decimals[i];
}
}
}
// Confirm and return the final output string:
if (outputCharacters == "") {
outputCharacters = CN_ZERO + CN_DOLLAR;
}
if (decimal == "") {
outputCharacters += CN_INTEGER;
}
if(isNegative==true)
{
outputCharacters = CN_SYMBOL + "负"+outputCharacters;
}
else
{
outputCharacters = CN_SYMBOL + outputCharacters;
}
return outputCharacters;
}
//----金额以千分位隔开
function transStr(str){
var begin ="";
var after ="";
var l;
var str2="";
if(str.indexOf(".")<0){
str=str+".00";
}
if(str.indexOf(".")>0){
begin = str.substring(0,str.indexOf("."));
after = str.substring(str.indexOf("."),str.length);
}else{
begin = str;
}
l=begin.length/3;
if(l>1){
for(var i=0;i<l; ){
str2=","+begin.substring(begin.length-3,begin.length)+str2;
begin=begin.substring(0,begin.length-3);
l=begin.length/3;
}
if(after.length<3){
str2=begin+str2+after+"0";
}else{
str2=begin+str2+after
}
return str2.substring(1);
}else{
if(after.length<3){
return str+"0";
}else{
return str;
}
}
}