create function [dbo].[f__numberchangeintoenglishuppercase]
(@num numeric(18,4))
returns varchar(400) --with encryption
asbegin
--declare @num numeric(17, 4) --支援到千億計數,保留四位小數
declare @i int,@hundreds int,@tenth int,@one int
declare @thousand int,@million int,@billion int
declare @numbers varchar(400),@s varchar(18),@result varchar(400)
--set @num = '1231231231.00121'
set @numbers='one two three four five '
+'six seven eight nine ten '
+'eleven twelve thirteen fourteen fifteen '
+'sixteen seventeen eighteen nineteen '
+'twenty thirty forty fifty '
+'sixty seventy eighty ninety '
set @s=right('000000000000000000'+cast(@num as varchar(17)),17)
set @billion=cast(substring(@s,1,3) as int)--將12位整數分成4段:十億、百萬、千、百十個
set @million=cast(substring(@s,4,3) as int)
set @thousand=cast(substring(@s,7,3) as int)
-- print '@thousand:'+convert( nvarchar(10),@thousand )
-- print '@million:'+convert( nvarchar(10),@million )
-- print '@billion:'+convert( nvarchar(10), @billion )
set @result=''
set @i=0
while @i<=3
begin
set @hundreds=cast(substring(@s,@i*3+1,1) as int)--百位0-9
set @tenth=cast(substring(@s,@i*3+2,1) as int)
set @one=(case @tenth when 1 then 10 else 0 end)+cast(substring(@s,@i*3+3,1) as int)--個位0-19
set @tenth=(case when @tenth<=1 then 0 else @tenth end)--十位0、2-9
if (@i=1 and @billion>0 and (@million>0 or @thousand>0 or @hundreds>0)) or
(@i=2 and (@billion>0 or @million>0) and (@thousand>0 or @hundreds>0)) or
(@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds>0))
set @result=@result+', '--百位不是0則每段之間加連線符,
if (@i=3 and (@billion>0 or @million>0 or @thousand>0) and (@hundreds=0 and (@tenth>0 or @one>0)))
set @result=@result+' and '--百位是0則加連線符and
if @hundreds>0
set @result=@result+rtrim(substring(@numbers,@hundreds*10-9,10))+' hundred'
if @tenth>=2 and @tenth<=9
begin
if @hundreds>0
set @result=@result+' and '
set @result=@result+rtrim(substring(@numbers,@tenth*10+171,10))
endif @one>=1 and @one<=19
begin
if @tenth>0
set @result=@result+'-'
else
if @hundreds>0
set @result=@result+' and '
set @result=@result+rtrim(substring(@numbers,@one*10-9,10))
endif @i=0 and @billion>0
set @result=@result+' billion'
if @i=1 and @million>0
set @result=@result+' million'
if @i=2 and @thousand>0
set @result=@result+' thousand'
set @i=@i+1
end
/*判斷是否有小數字*/
if substring(@s,14,4)<>'0000'
begin
set @result=@result+' point '
/*判斷小數點第一位數字是否不為零*/
if substring(@s,14,1)='0'
set @result=@result+'zero'
else
set @result = @result+rtrim(substring(@numbers,cast(substring(@s,14,1) as int)*10-9,10))
/*判斷小數點後第二位數字是否為零*/
if substring(@s,15,1)='0'
set @result=@result+' zero '
else
set @result = @result+rtrim(substring(@numbers,cast(substring(@s,15,1) as int)*10-9, 10))
/*判斷小數點後第三位數字是否為零*/
if substring(@s,16,1)='0'
set @result = @result+' zero '
else
set @result = @result+rtrim(substring(@numbers,cast(substring(@s,16,1) as int)*10-9, 10))
/*判斷小數點後第四位數字是否為零*/
if substring(@s,17,1)<>'0'
set @result = @result+' '+rtrim(substring(@numbers,cast(substring(@s,17,1) as int)*10-9,10))
else
set @result = @result+' zero'
end-- print '總字元:'+@s
-- print '大寫:'+@result
return(@result)
endselect dbo.f__numberchangeintoenglishuppercase(20098.9666)
Java 數字轉成英文
英文數詞,按3位3位區分 hundred 100 thousand 1,000 million 1,000,000 billion 1,000,000,000 trillion 1,000,000,000,000 quintillion 1,000,000,000,000,000,000 tilli...
Repeater呼叫儲存過程 數字分頁
default.aspx.cs using system using system.data using system.configuration using system.web using system.collections using system.web.security using sy...
批量刪除儲存過程的儲存過程
create procedure dropprocedure as declare cur cursor read only for select name from sysobjects where xtype p and name like drop declare name varchar 4...