php小写金额转大写

public static function amountInWords($num) {

if (!is_numeric($num) || empty($num))

return "";

$return = "";

$unit = array("分", "角", "圆", "整");

$dw = array("", "拾", "佰", "仟", "", "万", "亿", "兆");

$char = array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");

preg_match_all("/(\d*)\.?(\d*)/", $num, $ar);

if (intval($ar[2][0]) > 0) {

$return .= $ar[2][0][0] == 0 ? "" : $char[$ar[2][0][0]] . $unit[1];

if (isset($ar[2][0][1])) {

if (empty($return) && $ar[1][0] > 0)

$return = $char[0] . $char[$ar[2][0][1]] . $unit[0];

else

$return .= $char[$ar[2][0][1]] . $unit[0];

}

}else{

$return .= $unit[3];

}

if ($ar[1][0] != "") {

$str = strrev($ar[1][0]);

$len = strlen($str);

for ($i = 0; $i < $len; $i++) {

$out[$i] = $char[$str[$i]];

$out[$i] .= $str[$i] != "0"? $dw[$i%4] : "";

if ($str[$i] + $str[$i-1] == 0)

$out[$i] = "";

if ($i%4 == 0)

$out[$i] .= $dw[4+floor($i/4)];

if ($out[$i] == "零万")

$out[$i] = "万零";

}

$left = join("", array_reverse($out));

if (!empty($left))

$return = $left . $unit[2] . $return;

}

return $return;

}

时间: 2025-01-12 14:23:54

php小写金额转大写的相关文章

C#:小写金额转换为大写

#region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; if (Math.Abs(Currnum) < 1e-20) return "零圆整"; if (Currnum < 1e-20) sResult = "负"; sResult = sResult + StringToChnNum(Math.Abs(Mat

Oracle 小写金额转换为大写

在开发EBS的合同报表打印的时候需要将小写金额转换为大写. 如下是本人自己写的转换函数. 主要思路:先获取小数点位置,在区分整数与小数点处理,根据位数和数字组合读取金额. 最后再处理特殊显示部分. /******************************************************************* *  FUNCTION get_big_amount 数字金额转换为大写 *  p_amount 输入数据金额 *  返回大写金额,位数 :千亿----厘 ****

SQL标量值函数:小写金额转大写

我们日常开发业务系统中,作为统计报表中,特别是财务报表,显示中文金额经常遇到. 转换大小写的方法有很多,以下是从数据库函数方面解决这一问题. 效果如图: 调用:SELECT dbo.[Fn_ConvertRMB](192.4) 具体函数如下: -- ============================================= -- 调用:SELECT dbo.[Fn_ConvertRMB](192.4) -- Create date: 2015-01-06 -- Descripti

java将小写金额转换为大写的工具类

public class Tool {             private static final String UNIT = "万千佰拾亿千佰拾万千佰拾元角分";         private static final String DIGIT = "零壹贰叁肆伍陆柒捌玖";         private static final double MAX_VALUE = 9999999999999.99D;         public static St

金额小写转中文大写类

using System; using System.Collections.Generic; using System.Text; namespace Class_ZhH { /// <summary> /// 金额小写转中文大写类(附带一个数字转大写). /// 整数支持到万亿:小数部分支持到分(超过两位将进行Banker舍入法处理) /// </summary> public class NumGetString { private static String[] Ls_Sh

小写金额转换成大写 - 函数脚本

原文:小写金额转换成大写 - 函数脚本 /********************************************************作者:版本:创建时间:修改时间:功能:小写金额转换成大写参数:输出:大写金额********************************************************/ CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,2))RETURNS varchar(100) WI

SQL函数:小写金额转换成大写

/********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n_LowerMoney 小写金额v_TransType 种类 -- 1: directly translate, 0: read it in words 输出:大写金额********************************************************/if exists

JavaScript将小写金额转换成大写

//num为小写金额,单位元 changeMoney(num) { if(isNaN(num))return ""; var strPrefix=""; if(num<0)strPrefix ="(负)"; num=Math.abs(num); if(num>=1000000000000)return ""; var strOutput = ""; var strUnit = '仟佰拾亿仟佰拾万

BPM实例分享——金额规则大写

金额规则大写 在涉及金额的流程中经常会遇到需要大写金额数据与小写金额匹配,如何实现输入数字后自动转换呢? 初级用法: 1.在默认表单基本属性javascript 中增加如下金额转换方法 /** 数字金额大写转换(可以处理整数,小数,负数) */ function chineseNumber(dValue) { var maxDec = 2; // 验证输入金额数值或数值字符串: dValue = dValue.toString().replace(/,/g, ""); dValue =