File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ export function uppercaseNum ( n : number ) {
2+ const fraction = [ '角' , '分' ] ;
3+ const digit = [
4+ '零' , '壹' , '贰' , '叁' , '肆' ,
5+ '伍' , '陆' , '柒' , '捌' , '玖'
6+ ] ;
7+ const unit = [
8+ [ '元' , '万' , '亿' ] ,
9+ [ '' , '拾' , '佰' , '仟' ]
10+ ] ;
11+ const head = n < 0 ? '欠' : '' ;
12+ n = Math . abs ( n ) ;
13+ let s = '' ;
14+ for ( let i = 0 ; i < fraction . length ; i ++ ) {
15+ s += ( digit [ Math . floor ( n * 10 * Math . pow ( 10 , i ) ) % 10 ] + fraction [ i ] ) . replace ( / 零 ./ , '' ) ;
16+ }
17+ s = s || '整' ;
18+ n = Math . floor ( n ) ;
19+ for ( let i = 0 ; i < unit [ 0 ] . length && n > 0 ; i ++ ) {
20+ let p = '' ;
21+ for ( let j = 0 ; j < unit [ 1 ] . length && n > 0 ; j ++ ) {
22+ p = digit [ n % 10 ] + unit [ 1 ] [ j ] + p ;
23+ n = Math . floor ( n / 10 ) ;
24+ }
25+ s = p . replace ( / ( 零 .) * 零 $ / , '' ) . replace ( / ^ $ / , '零' ) + unit [ 0 ] [ i ] + s ;
26+ }
27+ return head + s . replace ( / ( 零 .) * 零 元 / , '元' )
28+ . replace ( / ( 零 .) + / g, '零' )
29+ . replace ( / ^ 整 $ / , '零元整' ) ;
30+ }
You can’t perform that action at this time.
0 commit comments