将人民币中的阿拉伯数字转换为大写
/**-----------人民币 大写转换
*
* @param num ----要转化的数字
* @return
*/
public static String makeUpperCaseSum(String numStr) {
String isNeg = "";//正或者负
double num = Double.parseDouble(numStr);
if (num < 0) {
num *= -1;
isNeg = "负";
numStr = numStr.substring(1);
}
final String[] upper_number = { "零","壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
final String[] number_dw = { "", "拾", "佰", "仟", "万", "拾", "佰",
"仟", "亿", "拾", "佰", "仟", "万" };
String operate = numStr;
String upper_str = "";
String upper_str_pre = "";
String upper_str_later = "";
String vsDx;
int i, j, point_pos, int_len;
if (num < 0.01) {
return "零圆整";
}
upper_str_pre = "";
point_pos = operate.indexOf(".");
if (point_pos == -1) {
int_len = operate.length();
} else {
int_len = point_pos;
}
if (int_len > number_dw.length) {
return "too long !!!";
}
if (num > 0) {
for (i = 0; i < operate.length(); i++) {
j = int_len - i;
if(j>0){//整数部分
int k = Integer.parseInt(operate.substring(i, i + 1));
if(k==0){//数字为0时
if(j==5||j==9)//单位为亿或者万时
upper_str_pre += upper_number[k] + number_dw[j-1];
else
upper_str_pre += upper_number[k];
}
else
upper_str_pre += upper_number[k] + number_dw[j-1];
}else if(j<0){//小数部分
int k = Integer.parseInt(operate.substring(i, i + 1));
upper_str_later += upper_number[k];
if(j==-1)
upper_str_later += "角";
else
upper_str_later += "分";
}
} //end for
} //end if
upper_str_pre += "圆";
while(upper_str_pre.indexOf("零零")!=-1){
upper_str_pre = upper_str_pre.replaceAll("零零","零");
}
upper_str_pre = upper_str_pre.replaceAll("零万","万");
upper_str_pre = upper_str_pre.replaceAll("零亿","亿");
upper_str_pre = upper_str_pre.replaceAll("亿万","亿零");
upper_str_pre = upper_str_pre.replaceAll("零零","零");
upper_str_pre = upper_str_pre.replaceAll("零圆","圆");
if("圆".equals(upper_str_pre))
upper_str_pre = "";
upper_str = isNeg+upper_str_pre + upper_str_later;
upper_str = upper_str.replaceAll("零角零分","整");
if(point_pos == -1)
upper_str += "整";
return upper_str;
}
sql function实现:
create or replace function changeToCap(number_string varchar2,pos number) return varchar2 is
Result varchar2(100);
i number;
begin
i:=1;
if pos<=length(number_string) then
if substr(number_string,length(number_string)-pos+1,1)='0' then
Result:='零';
elsif substr(number_string,length(number_string)-pos+1,1)='1' then
Result:='壹';
elsif substr(number_string,length(number_string)-pos+1,1)='2' then
Result:='贰';
elsif substr(number_string,length(number_string)-pos+1,1)='3' then
Result:='叁';
elsif substr(number_string,length(number_string)-pos+1,1)='4' then
Result:='肆';
elsif substr(number_string,length(number_string)-pos+1,1)='5' then
Result:='伍';
elsif substr(number_string,length(number_string)-pos+1,1)='6' then
Result:='陆';
elsif substr(number_string,length(number_string)-pos+1,1)='7' then
Result:='柒';
elsif substr(number_string,length(number_string)-pos+1,1)='8' then
Result:='捌';
elsif substr(number_string,length(number_string)-pos+1,1)='9' then
Result:='玖';
end if;
else
Result:='';
end if;
return(Result);
end changeToCap;
应用function:
select ttc.tujian_total_cost,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),6) as shiwan,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),5) as wan,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),4) as qian,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),3) as bai,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),2) as shi,
changetocap(substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1),1) as ge,
'¥'||substr(ttc.tujian_total_cost,0,instr(ttc.tujian_total_cost,'.')-1) as lowercase
from T_TUJIAN_CHARGE ttc where ttc.modify_flag<>'D' and ttc.charge_id='100000023'
//中文大写金额转换函数,包括币制单位
CREATE OR REPLACE Function changeUppMoney(numMoney in Number)
RETURN VARCHAR2
IS strMoney VARCHAR2(60);
strSign varchar2(4);
numValue number(22);
strNum Varchar2(2);
strBit Varchar2(2);
numBit number(2);
numMod Number(1);
strUppNum VARCHAR2(20):='零壹贰叁肆伍陆柒捌玖';
strUppUnit VARCHAR2(34):='分角圆拾佰仟万拾佰仟亿拾佰仟万拾佰';
BEGIN
if numMoney<0 then
strSign:='[负]';
else
strSign:='';
end if;
numValue:=abs(numMoney)*100;
strMoney:='';
numBit:=0;
LOOP
numMod:=Mod(numValue,10);
strNum:=substr(strUppNum,numMod+1,1);
strBit:=substr(strUppUnit,numBit+1,1);
strMoney:=strNum||strBit||strMoney;
numValue:=FLOOR(numValue/10);
numBit:=numBit+1;
exit when numValue<1 or numBit>16;
END LOOP;
strMoney:=replace(strMoney,'零角','零');
strMoney:=replace(strMoney,'零仟','零');
strMoney:=replace(strMoney,'零佰','零');
strMoney:=replace(strMoney,'零拾','零');
strMoney:=replace(strMoney,'零零','零');
strMoney:=replace(strMoney,'零零','零');
strMoney:=replace(strMoney,'零分','整');
strMoney:=replace(strMoney,'零圆','圆');
strMoney:=replace(strMoney,'零万','万');
strMoney:=replace(strMoney,'零亿','亿');
strMoney:=replace(strMoney,'亿万','亿');
strMoney:=strSign||strMoney;
RETURN(strMoney);
END;
//中文大写数字转换函数,不包括币制单位,可指定空格填充,用于单据套打等场合:
CREATE OR REPLACE Function changeUppNumber(numMoney in Number,numSpace in Number)
RETURN VARCHAR2
IS strMoney VARCHAR2(200);
strSign varchar2(4);
numValue number(22);
strNum Varchar2(20);
numLen number(2);
numBit number(2);
numMod Number(1);
strUppNum VARCHAR2(20):='零壹贰叁肆伍陆柒捌玖';
BEGIN
if numSpace>10 then
numLen:=12;
else
numLen:=numSpace+2;
end if;
if numMoney<0 then
strSign:='[负]';
else
strSign:='';
end if;
numValue:=abs(numMoney)*100;
strMoney:='';
numBit:=0;
LOOP
numMod:=Mod(numValue,10);
strNum:=lpad(substr(strUppNum,numMod+1,1),numLen);
strMoney:=strNum||strMoney;
numValue:=FLOOR(numValue/10);
numBit:=numBit+1;
exit when numValue<1 or numBit>16;
END LOOP;
strMoney:=strSign||strMoney;
RETURN(strMoney);
END;