我自己做了一个,应该可以的。 create or replace function getchinesenum( /* 2006-03-26 最多允许小数点后保留两位有效数(即保留到分) 最大值为999999999999.99 (玖千玖百玖拾玖亿玖千玖百玖拾玖万玖千玖百玖拾玖点玖玖元) **/
p_input number) return varchar2 as rv varchar2(4000); tmpstr varchar(4000); m varchar(4000); k varchar(4000); i numeric(38, 2); j int; lastj int; lastv varchar(10); lastf varchar(10); laste varchar(10); lastve varchar(10); begin i := p_input; tmpstr := '零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟'; k := ''; m := to_char(i * 100); -- cast(cast( as bigint) as varchar(800)), j := length(m); lastve := ''; lastv := ''; while j >= 1 loop lastf := substr(tmpstr, to_number(substr(m, length(m) - j + 1, 1)) + 1, 1); laste := substr(tmpstr, 10 + j, 1); if lastf <> '零' then if lastv = '零' then if (lastj >= 7 and j <= 7) or (lastj >= 11 and j <= 11) or (lastj >= 3 and j <= 2) then if j <= 2 and lastj <= 3 then k := k || lastve || lastf || laste; else k := k || lastve || lastv || lastf || laste; end if; else k := k || lastv || lastf || laste; end if; else k := k || lastf || laste; end if; lastj := j; lastve := '';
elsif lastf = '零' then if lastj > 11 then lastve := '亿'; end if; if lastj > 7 and lastj < 10 then lastve := '万'; end if; if (lastj > 3) and (lastj < 6) then lastve := '元'; end if; if lastv <> '零' then lastj := j; end if; end if; lastv := lastf; j := j - 1; end loop; if lastj >= 3 then k := k || '元'; end if; if lastj >= 2 then k := k || '整'; end if; rv := k; return rv; end getchinesenum; 调用 select getchinesenum(300059) from dual 叁拾万零伍拾玖元整
/// 将阿拉伯数字表示的货币数表示成中文大写的货币数(如将"34567.23"转换为"叁万肆仟伍佰陆拾柒元贰角叁分"),如果单位是万元请将输入数字乘以10000;能表示的金额上限为十万亿元
/// </summary>
/// <param name="inputString">阿拉伯数字表示的货币数如:34567.23</param>
/// <returns>大写中文表示的货币数如:叁万肆仟伍佰陆拾柒元贰角叁分</returns>
public static string ConvertToChineseNum(string inputString)
{
string numList="零壹贰叁肆伍陆柒捌玖";
string rmbList = "分角元拾佰仟万拾佰仟亿拾佰仟万";
double number=0;
string tempOutString=null;
string outString=null; number=double.Parse(inputString);
if(number>9999999999999.99)
throw new Exception("数字过大,无法用中文来表示"); //将小数转化为整数字符串
string tempNumberString=Convert.ToInt64(number*100).ToString();
int tempNmberLength=tempNumberString.Length;
int i=0;
while(i<tempNmberLength)
{
int oneNumber=Int32.Parse(tempNumberString.Substring(i,1));
string oneNumberChar=numList.Substring(oneNumber,1);
string oneNumberUnit=rmbList.Substring(tempNmberLength-i-1,1);
if(oneNumberChar!="零")
tempOutString+=oneNumberChar+oneNumberUnit;
else
{
if(oneNumberUnit=="亿"||oneNumberUnit=="万"||oneNumberUnit=="元"||oneNumberUnit=="零")
{
while (tempOutString.EndsWith("零"))
{
tempOutString=tempOutString.Substring(0,tempOutString.Length-1);
} }
if(oneNumberUnit=="亿"||(oneNumberUnit=="万"&&!tempOutString.EndsWith("亿"))||oneNumberUnit=="元")
{
tempOutString+=oneNumberUnit;
}
else
{
bool tempEnd=tempOutString.EndsWith("亿");
bool zeroEnd=tempOutString.EndsWith("零");
if(tempOutString.Length>1)
{
bool zeroStart=tempOutString.Substring(tempOutString.Length-2,2).StartsWith("零");
if(!zeroEnd&&(zeroStart||!tempEnd))
tempOutString+=oneNumberChar;
}
else
{
if(!zeroEnd&&!tempEnd)
tempOutString+=oneNumberChar;
}
}
}
i+=1;
} while (tempOutString.EndsWith("零"))
{
tempOutString=tempOutString.Substring(0,tempOutString.Length-1);
} while(tempOutString.EndsWith("元"))
{
tempOutString=tempOutString+"整";
} outString=tempOutString;
return outString;
}
oralce中如何实现将数字转换为大写
oralce中如何实现将数字转换为大写
这个也能用啊,取出来,转一下,更新一下,这样就行了啊。不懂...
create or replace function getchinesenum( /* 2006-03-26
最多允许小数点后保留两位有效数(即保留到分)
最大值为999999999999.99 (玖千玖百玖拾玖亿玖千玖百玖拾玖万玖千玖百玖拾玖点玖玖元)
**/
p_input number) return varchar2 as
rv varchar2(4000);
tmpstr varchar(4000);
m varchar(4000);
k varchar(4000);
i numeric(38, 2);
j int;
lastj int;
lastv varchar(10);
lastf varchar(10);
laste varchar(10);
lastve varchar(10);
begin
i := p_input;
tmpstr := '零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟';
k := '';
m := to_char(i * 100); -- cast(cast( as bigint) as varchar(800)),
j := length(m);
lastve := '';
lastv := '';
while j >= 1 loop
lastf := substr(tmpstr,
to_number(substr(m, length(m) - j + 1, 1)) + 1,
1);
laste := substr(tmpstr, 10 + j, 1);
if lastf <> '零' then
if lastv = '零' then
if (lastj >= 7 and j <= 7) or (lastj >= 11 and j <= 11) or
(lastj >= 3 and j <= 2) then
if j <= 2 and lastj <= 3 then
k := k || lastve || lastf || laste;
else
k := k || lastve || lastv || lastf || laste;
end if;
else
k := k || lastv || lastf || laste;
end if;
else
k := k || lastf || laste;
end if;
lastj := j;
lastve := '';
elsif lastf = '零' then
if lastj > 11 then
lastve := '亿';
end if;
if lastj > 7 and lastj < 10 then
lastve := '万';
end if;
if (lastj > 3) and (lastj < 6) then
lastve := '元';
end if;
if lastv <> '零' then
lastj := j;
end if;
end if;
lastv := lastf;
j := j - 1;
end loop;
if lastj >= 3 then
k := k || '元';
end if;
if lastj >= 2 then
k := k || '整';
end if;
rv := k;
return rv;
end getchinesenum;
调用
select getchinesenum(300059) from dual
叁拾万零伍拾玖元整