網誌分頁

中文數字的JavaScript函式

自己會寫涵式了 每次遇到繁雜的CODE就想自己以涵式的方式寫一寫  以後還可以用的到

以下是JAVASCRIPT的中文數字的涵式,COPY這個到HEAD裡以後再用chineseNum(330)來呼叫他,就可以把阿拉伯數字變成我們古色古香的中國字摟!

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function chineseNum(numstr){
        numArray='零,一,二,三,四,五,六,七,八,九,十'.split(',');
        decimalArray='個,十,百,千,萬,十,百,千,億,十,百,千,兆'.split(',');
        tmpstr=new String();
        for(counti=0;counti<numstr.toString().length;counti++){
 
            decimalPlace=numstr.toString().length-counti-1;
            if(!(decimalPlace==2  && numstr.toString().charAt(counti)!=1 && numstr.toString().length==2) &&  numstr.toString().charAt(counti)!=0){
 
                tmpstr+=numArray[numstr.toString().charAt(counti)];
            }
 
            if(decimalPlace>0 ){
            tmpstr+=decimalArray[decimalPlace];
            }
 
        }
        return tmpstr;
    }

Related posts:

  1. 判定你的變數是否存在 寫程式的人,大概都寫不下幾千幾萬個IF來判定變數是否存在,這也許是繼Hello World另一個最多的程式了吧。 於ColdFusion的判定變數,只需加個isdefined(變數名稱的字串) 即可: if(isdefined{'myValue')){ return true; }else{ return false;...

Related posts brought to you by Yet Another Related Posts Plugin.

4 comments to 中文數字的JavaScript函式

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>