php實現數字金額轉換成中文大寫金額

2022-08-26 20:00:16 字數 961 閱讀 9844

<?php

header("content-type : text/html ;charset=utf-8");/**

*數字金額轉換成中文大寫金額的函式

*string int $num 要轉換的小寫數字或小寫字串

*return 大寫字母

*小數字為兩位

**/function num_to_rmb($num

)

$i = 0;

$c = "";

while ( 1)

else

//每次將最後一位數字轉化為中文

$p1 = substr ( $c1, 3 * $n, 3);

$p2 = substr ( $c2, 3 * $i, 3);

if ($n != '0' || ($n == '0' && ($p2 == '億' || $p2 == '萬' || $p2 == '元')))

else

$i = $i + 1;

//去掉數字最後一位了

$num = $num / 10;

$num = ( int ) $num

;

//結束迴圈

if ($num == 0)

}$j = 0;

$slen = strlen ( $c

);

while ( $j

< $slen

)

$j = $j + 3;

}//這個是為了去掉類似23.0中最後乙個「零」字

if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零')

//將處理的漢字加上「整」

if (empty ( $c

))

else

}echo num_to_rmb ( 2340555.34 );

PHP數字金額轉換成中文大寫金額

封裝函式如下 數字金額轉換成中文大寫金額的函式 string int num 要轉換的小寫數字或小寫字串 return 大寫字母 小數字為兩位 function numtormb num i 0 c while 1 else 每次將最後一位數字轉化為中文 p1 substr c1,3 n,3 p2 ...

數字金額轉換成中文金額(C 實現)

public static string convertnumamttochinese decimal numval switch j ret temp ret ret ret.replace 零拾 零 ret ret.replace 零佰 零 ret ret.replace 零仟 零 ret re...

小寫金額轉換成中文大寫金額

public string cmycurd decimal num str2 str2.substring 15 j 取出對應位數的str2的值。如 200.55,j為5所以str2 佰拾元角分 迴圈取出每一位需要轉換的值 for i 0 i j i else else else else else...