Home>
//The code is as follows:
function convertcurrency (money) {
  //Chinese characters
  var cnnums=new array ("zero", "one", "two", "three", "three", "wu", "lu", "SEVEN", "eight", "Jiu");
  //basic unit
  var cnintradice=new array ("", "Shi", "Bai", "thousand");
  //Corresponding integer part expansion unit
  var cnintunits=new array ("", "Ten thousand", "Billion", "Mega");
  //Corresponds to the decimal part unit
  var cndecunits=new array ("angle", "minute", "milli", "cent");
  //character followed by integer amount
  var cninteger="whole";
  //Unit after integer
  var cnintlast="Meta";
  //Maximum number processed
  var maxnum=999999999999999.9999;
  //Amount integer part
  var integernum;
  //Amount fraction
  var decimalnum;
  //Chinese character string output
  var chinesestr="";
  //Array used after separating amounts,Predefined
  var parts;
  if (money == "") {return "";}
  money=parsefloat (money);
  if (money>= maxnum) {
    //Exceed the maximum processing number
    return "";
  }
  if (money == 0) {
    chinesestr=cnnums [0] + cnintlast + cninteger;
    return chinesestr;
  }
  //Convert to string
  money=money.tostring ();
  if (money.indexof (".") == -1) {
    integernum=money;
    decimalnum="";
  } else {
    parts=money.split (".");
    integernum=parts [0];
    decimalnum=parts [1] .substr (0, 4);
  }
  //Get integer conversion
  if (parseint (integernum, 10)&0;{
    var zerocount=0;
    var intlen=integernum.length;
    for (var i=0;i<intlen;i ++) {
      var n=integernum.substr (i, 1);
      var p=intlen-i-1;
      var q=p/4;
      var m=p%4;
      if (n == "0") {
        zerocount ++;
      } else {
        if (zerocount>0) {
          chinesestr +=cnnums [0];
        }
        //Return to zero
        zerocount=0;
        chinesestr +=cnnums [parseint (n)] + cnintradice [m];
      }
      if (m == 0&&zerocount<4) {
        chinesestr +=cnintunits [q];
      }
    }
    chinesestr +=cnintlast;
  }
  //decimal part
  if (decimalnum!="") {
    var declen=decimalnum.length;
    for (var i=0;i<declen;i ++) {
      var n=decimalnum.substr (i, 1);
      if (n!="0") {
        chinesestr +=cnnums [number (n)] + cndecunits [i];
      }
    }
  }
  if (chinesestr == "") {
    chinesestr +=cnnums [0] + cnintlast + cninteger;
  } else if (decimalnum == "") {
    chinesestr +=cninteger;
  }
  return chinesestr;
}

RMB Caps Online Conversion Tool:

  • Previous Python implements SMTP sending email detailed tutorial
  • Next AngularJS basic ng-model-options directive simple example