zoukankan      html  css  js  c++  java
  • JS人民币金额转大写程序

    1. //人民币金额转大写程序 JavaScript版     
    2. //CopyRight Bardo QI     
    3.     
    4. function numToCny(num){     
    5.     var capUnit = ['万','亿','万','圆',''];     
    6.     var capDigit = { 2:['角','分',''], 4:['仟','佰','拾','']};     
    7.     var capNum=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];     
    8.     if (((num.toString()).indexOf('.') > 16)||(isNaN(num)))      
    9.         return '';     
    10.     num = (Math.round(num*100)/100).toString();     
    11.     num =((Math.pow(10,19-num.length)).toString()).substring(1)+num;     
    12.     var i,ret,j,nodeNum,k,subret,len,subChr,CurChr=[];     
    13.     for (i=0,ret='';i<5;i++,j=i*4+Math.floor(i/4)){     
    14.         nodeNum=num.substring(j,j+4);     
    15.         for(k=0,subret='',len=nodeNum.length;((k<len) && (parseInt(nodeNum.substring(k))!=0));k++){     
    16.             CurChr[k%2] = capNum[nodeNum.charAt(k)]+((nodeNum.charAt(k)==0)?'':capDigit[len][k]);     
    17.             if (!((CurChr[0]==CurChr[1]) && (CurChr[0]==capNum[0])))     
    18.                 if(!((CurChr[k%2] == capNum[0]) && (subret=='') && (ret=='')))     
    19.                     subret += CurChr[k%2];     
    20.         }     
    21.         subChr = subret + ((subret=='')?'':capUnit[i]);     
    22.         if(!((subChr == capNum[0]) && (ret=='')))     
    23.             ret += subChr;     
    24.     }     
    25.     ret=(ret=='')? capNum[0]+capUnit[3]: ret;       
    26.     return ret;     
    27. }   

     

  • 相关阅读:
    Using CocoaPods
    IMPROVING IOS UNIT TESTS WITH OCMOCK
    梦想不为斗室所缚
    【转】class 'org.springframework.orm.hibernate3.LocalSessionFactoryBean' not found解决办法
    我们去工作是为了什么?——迈锡尼
    查看已保存的wifi密码
    点球成金
    研究生开口月薪一万 企业暗示“靠边站”
    程序员技术练级攻略
    Emacs是一种信仰!世界最强编辑器介绍 (转自王珢)
  • 原文地址:https://www.cnblogs.com/Look_Sun/p/2033319.html
Copyright © 2011-2022 走看看