代码如下 复制代码
// 函数名:exchangemoney($n_money)
// 作 用:资金转换函数
// 参 数:$n_money(待转换的金额数字)
// 返回值:字符串
// 备 注:本函数示例:$char=exchangemoney(5645132.3155) ==> $char='¥5,645,132.31'
//-----------------------------------------------------------------------------------
function exchangemoney($n_money)
{
$a_tmp=explode(.,$n_money ); //将数字按小数点分成两部分,并存入数组$a_tmp
$i_len=strlen($a_tmp[0]); //测出小数点前面位数的宽度
if($i_len%3==0)
{
$i_step=$i_len/3; //如前面位数的宽度mod 3 = 0 ,可按,分成$i_step 部分
}else
{
$step=($len-$len%3)/3+1; //如前面位数的宽度mod 3 != 0 ,可按,分成$i_step 部分+1
}
$c_cur=;
//对小数点以前的金额数字进行转换
while($i_len0)
{
$i_step--;
if($i_step==0)
{
$c_cur .= substr($a_tmp[0],0,$i_len-($i_step)*3);
}else
{
$c_cur .= substr($a_tmp[0],0,$i_len-($i_step)*3).,;
}
$a_tmp[0]=substr($a_tmp[0],$i_len-($i_step)*3);
$i_len=strlen($a_tmp[0]);
}
//对小数点后面的金额的进行转换
if($a_tmp[1]==)
{
$c_cur .= .00;
}else
{
$i_len=strlen($a_tmp[1]);
if($i_len<2)
{
$c_cur .= ..$a_tmp[1].0;
}else
{
$c_cur .= ..substr($a_tmp[1],0,2);
}
}
//加上人民币符号并传出
$c_cur=¥.$c_cur;
return $c_cur;
}
http://www.bkjia.com/phpjc/631665.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/631665.htmltecharticle文章介绍一个自定的资金转换函数,可以根据用户输入的信息转换成银行格式资金格式,有需要以同学可以参考一下。 代码如下 复制代码...
