//这是java Script脚本的金额大小写转换
<%@ page contentType="text/html; charset=gb2312" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/JavaScript">
<!--
function Print()
{
WB.ExecWB(6,1);
}
function init(){
var io = convertCurrency(total_value.value);
var Digits=200;
document.forms[0].Result.value = convertCurrency(Digits);
}
function convertCurrency(currencyDigits) {
// Constants:
var MAXIMUM_NUMBER = 99999999999.99;
// Predefine the radix characters and currency symbols for output:
var CN_ZERO = "零";
var CN_ONE = "壹";
var CN_TWO = "贰";
var CN_THREE = "叁";
var CN_FOUR = "肆";
var CN_FIVE = "伍";
var CN_SIX = "陆";
var CN_SEVEN = "柒";
var CN_EIGHT = "捌";
var CN_NINE = "玖";
var CN_TEN = "拾";
var CN_HUNDRED = "佰";
var CN_THOUSAND = "仟";
var CN_TEN_THOUSAND = "万";
var CN_HUNDRED_MILLION = "亿";
var CN_SYMBOL = "¥ ";
var CN_DOLLAR = "元";
var CN_TEN_CENT = "角";
var CN_CENT = "分";
var CN_INTEGER = "整";
var CN_INTEGER0 = "零角零分";
var CN_INTEGER1 = "零分";
// Variables:
var integral; // Represent integral part of digit number.截取数字的整数部分
var decimal; // Represent decimal part of digit number.截取数字的小数部分
var outputCharacters; // The output result.输出的结果
var parts;//以parts作为截取字符串的字符
var digits, radices, bigRadices, decimals;
var zeroCount;//零点计数
var i, p, d;
var quotient, modulus;//商,模
// Validate input string:取传进来的数字转换成字符串
//currencyDigits = currencyDigits.toString();
// if (currencyDigits == "") {
// alert("Empty input!");
// return "";
//}
//if (currencyDigits.match(/[^,.\d]/) != null) {
// alert("Invalid characters in the input string!");
// return "";
// }
//if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
// alert("Illegal format of digit number!");
//return "";
// }
// Normalize the format of input digits:
// currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
// currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
// Assert the number is not greater than the maximum number.
// if (Number(currencyDigits) > MAXIMUM_NUMBER) {
// alert("Too large a number to convert!");
// return "";
// }
// Process the coversion from currency digits to characters:
// Separate integral and decimal parts before processing coversion:
parts = currencyDigits.split(".");//字符串以小数点分
if (parts.length > 1) {//如果有小数,分为2部分
integral = parts[0];
decimal = parts[1];
// Cut down redundant decimal digits that are after the second.
decimal = decimal.substr(0, 2);//保留2为小数
}
else {//否则只取整数部分
integral = parts[0];
decimal = "";
}
// Prepare the characters corresponding to the digits:定义所需要的数组
digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);//零到九
radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);//十,百,千
bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);//万,亿
decimals = new Array(CN_TEN_CENT, CN_CENT);//角,分
// Start processing:
outputCharacters = "";//初始化变量
// Process integral part if it is larger than 0:
if (Number(integral) > 0) //如果整数部分大于零
{
zeroCount = 0;//定义零计数变量
for (i = 1; i < integral.length+1; i++)//定义循环,
{
p = integral.length - i;//整数的字符串长度减一位
d = integral.substr(i-1, 1);//取到当前循环到的数字
quotient = p / 4;//取商
modulus = p % 4;//取余数
if (d == "0") //如果当前数字为零
{
zeroCount++; //零计数器加一位
}
else //如果当前数字不为零
{
if (zeroCount > 0) //如果零计数器大于零
{
outputCharacters += digits[0];//值后面加零
}
zeroCount = 0;//重新赋零计数器值为零
outputCharacters += digits[Number(d)] + radices[modulus];//返回结果
}
if (modulus == 0 && zeroCount < 4) //如果模为一且零计数器小于4
{
outputCharacters += bigRadices[quotient];//
}
}
outputCharacters += CN_DOLLAR;//返回最后结果
}
// Process decimal part if there is:
if (decimal != "") {
for (i = 0; i < decimal.length; i++) {
d = decimal.substr(i, 1);
if (d != "000") {
outputCharacters += digits[Number(d)] + decimals[i];
}
}
if(decimal.length<2){
outputCharacters +=CN_INTEGER1;
}
}
// Confirm and return the final output string:
if (outputCharacters == "") {
outputCharacters = CN_ZERO + CN_DOLLAR;
}
if (decimal == "") {
outputCharacters += CN_INTEGER0;
}
outputCharacters = CN_SYMBOL + outputCharacters;
return outputCharacters;
}
//-->
</script>
</head>
<body>
<INPUT id="Digits" type="text" name="Digits" size=20>
<INPUT id="Convert" type="button" value="Convert" name="Convert" onclick="Result.value = convertCurrency(Digits.value);">
<INPUT id="Result" type="text" name="Result" size=60>
</body>
</html>
//我根据上面的脚本,改成的Pascle Script脚本用于公司的报表工具(数巨报表),并且增加了对正负数的
//判断,贴上来臭屁一下
begin
outputChar:=''; //初始化返回变量为空
//定义0-9数字数组
digits[0]:='零';digits[1]:='壹';digits[2]:='贰';digits[3]:='叁';digits[4]:='肆';digits[5]:='伍';digits[6]:='陆';
digits[7]:='柒';digits[8]:='捌';digits[9]:='玖';
//定义十,百,千
radices[0]:=''; radices[1]:='拾';radices[2]:='佰';radices[3]:='仟';
//定义万,亿
bigRadices[0]:=''; bigRadices[1]:='万';bigRadices[2]:='亿';
//定义角,分
decimals[1]:='角'; decimals[2]:='分';
CN_DOLLAR:='元';
//<CustomerData.az."salary">为你数据源中需要转换的字段,这个是主数据邦定的字段,替换下面的1005
integ:=[EXTRACTWORD(1,'-1005','.')]; // 截取数字的整数部分
decimal:=[EXTRACTWORD(2,'-1005','.')]; // 截取数字的小数部分
decimal:=leftcopy(decimal,2); //保留2为小数
if [COPY(integ, 1,1)]='-' then //判断首位符号确认正负
begin
integ:=[COPY(integ, '2', [LENGTH(integ)-1])];//去掉负数的标志后的数点左边的字符串
if integ>0 then //如果整数部分大于零
begin
i:=1; //定义循环的整形初始变量
zeroCount:=0; ////定义零计数变量
while i<length(integ)+1 do //定义循环,
begin
p:=length([integ])-i; //整数的字符串长度减一位
d:=copy(str([integ]),i,1); //取到当前循环到的数
quotient:=p/4; //用于下面判断,根据p取商
modulus:=p mod 4; //用于下面判断,根据p取模
if d=0 then //如果当前数字为零
zeroCount:=zeroCount+1 //零计数器加一位
else
begin //如果零计数器大于零
if zeroCount>0 then
begin //值后面加零
outputChar:=str([outputChar])+digits[0];
end;
//重新赋计数器值为零
zeroCount:=0;
//返回结果
outputChar:=str([outputChar])+digits[strtoint([d])]+radices[modulus];
end;
//如果模为一且零计数器小于4,判断过千过万的数
if ((modulus=0) and (zeroCount<4)) then
begin
outputChar:=str([outputChar])+bigRadices[quotient];
end;
//到下一位进行判断
i:=i+1;
end;
//返回整书部分结果
outputChar:='负'+outputChar+CN_DOLLAR;
end ;
end
else
begin
if integ>0 then
begin
zeroCount:=0; i:=1;
// outputChar:=length([integ])-i-1;
while i<length(integ)+1 do
begin
p:=length([integ])-i;
d:=copy(str([integ]),i,1);
quotient:=p/4;
modulus:=p mod 4;
//outputChar:=p;
if d=0 then
zeroCount:=zeroCount+1
else
begin
if zeroCount>0 then
begin
outputChar:=str([outputChar])+digits[0];
end;
zeroCount:=0;
outputChar:=str([outputChar])+digits[strtoint([d])]+radices[modulus];
end;
if ((modulus=0) and (zeroCount<4)) then
begin
outputChar:=str([outputChar])+bigRadices[quotient];
end;
i:=i+1;
end;
//outputChar:=p;
//outputChar:=digits[strtoint(d)]
outputChar:=outputChar+CN_DOLLAR;
//outputChar:=p;
//outputChar:=i;
end ;
end;
//小书部分的判断类似整数
if decimal <> '' then
begin
e:=0;
while e<length([decimal]) do
begin
e:=e+1;
f:=copy(str([decimal]),e,1);
if f<>'0' then
begin
outputChar:=outputChar + digits[strtoint([f])] + decimals[e];
end;
end;
end
end