PHP 数字转为大写金额(面向对象版)
本人在网上找了很久都没个完整能用的,于是只好自己写个(有效位数整数部分至千万亿,小数部分至小数点后四位),在此提供给其他在项目中有需要的PHPer们,如果测得Bug请发邮件于Widesky520@http://www.doczj.com/doc/d2f8d27c31b765ce050814eb.html ,会尽快更新。另还有个过程版的,有需要的也可用那个。
$time_start=getmicrotime();
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
/// CLASS BEGIN //
class Num2cny
{
/** 大写数字*/
private $cny_num = array('零','壹','贰','参','肆','伍','陆','柒','捌','玖');
/** 整数部分的单位*/
private $cny_int_unit = array('圆','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟','万','拾','佰','仟');
/** 小数部分的单位*/
private $cny_dec_unit = array('角','分','厘','毫');
/** 大于1吗*/
private $greater_than_1 = FALSE;
/**
* 转为大写金额。
* @access public
* @param string
* @return string
*/
public function conversion($str) {
if(empty($str))
{
return 'Please input a numeric value!';
}
if( ! is_numeric($str))
{
return 'It is not a numeric value!';
}
$str = str_replace(',','',trim($str));// 过滤掉左右空格和逗号
$str = ltrim($str,'0');
$_integerStr = '';// 整数部分数字
$_decimalStr = '';// 小数部分数字