php 數字金額轉漢字大寫金額

2021-10-22 05:56:30 字數 2004 閱讀 2007

數字金額轉漢字金額

// 測試

public

function

testnum()

/** * 數字金額轉漢字金額

** @param float $money 數字金額

* @param int $type 已棄用

* @return string 漢字金額

*/public

function

numtormb

($money

,$type=0

)$money

=round

($money,2

);//只保留兩位有效數字

dump

($money);

list

($int

,$dec)=

explode

("."

,$money,2

);$cnynums=[

'零',

'壹',

'貳',

'叄',

'肆',

'伍',

'陸',

'柒',

'捌',

'玖']

;$cnygre=[

'拾',

'佰',

'仟',

'萬',

'拾',

'佰',

'仟',

'億',

'拾',

'佰',

'仟']

;// 整數部分操作

$str=''

;//返回的字串

$ist

=false

;// 是否已經填過一次'零'

$len

=strlen

($int)-

1;$i=

$len

;while($i

>=0)

// 儲存 萬、億等單位if(

$i%4==

0&&$i>0)

if(mb_substr

($str,-

1,1)

!='億'

)$ist

=false;}

}else}--

$i;}// 如果漢字金額末尾包含 零, 則刪除if(

mb_substr

($str,-

1,1)

=='零'

)$i***istint

=true

;// 是否存在整數部分if(

empty

($str))

$str.=

$this

->

numtormbdec

($dec

,$i***istint

,$type);

return

$str;}

/** * 數字金額轉漢字金額

* 小數部分

* @param float $dec 小數金額

* @param bool $i***istint true 存在整數部分 false 不存在

* @param int $type 已棄用

* @return string 漢字金額

*/public

function

numtormbdec

($dec

,$i***istint

,$type=0

)$str

=$i***istint

==true

?'圓':''

;$str.=

$cnynums

[$dec[0

]];if

($dec[0

]!=0)

if(empty

($dec[1

]))$str.=

$cnynums

[$dec[1

]].'分'

;return

$str

;}

C 數字轉漢字大寫金額

private static string nums 零壹貳叄肆伍陸柒捌玖 private static string units 仟佰拾萬仟佰拾億仟佰拾萬仟佰拾元角分釐 string valuestr value.tostring 0000000000000000.000 valuestr val...

數字金額轉中文大寫金額

用來將數字金額轉化成中文大寫的金額 param value return public static string changetobig double value 段內位置表示 char vunit 段名表示 char digit 數字表示 decimalformat df new decimal...

c 數字金額轉大寫金額

static string moneytoupper string stramount string strlower null string strupart null string strupper null int itemp 0 保留兩位小數 123.489 123.49 123.4 123...