如何將阿拉伯數字寫成英文數字

2021-04-29 23:38:11 字數 4768 閱讀 9933

create

function

[dbo].

[f_num_eng](

@num

numeric(15,

2))returns

varchar

(400

) with

encryption

asbegin

--declare

@iint

,@hundreds

int,

@tenth

int,

@one

intdeclare

@thousand

int,

@million

int,

@billion

intdeclare

@numbers

varchar

(400

),@s

varchar(15

),@result

varchar

(400

)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('

000000000000000'+

cast

(@num

asvarchar(15

)),15

)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)

set@result=''

set@i=0

while

@i<=

3begin

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

1then

10else

0end)+

cast

(substring(@s

,@i*3

+3,1

) as

int)

--個位0-19

set@tenth=(

case

when

@tenth

<=

1then

0else

@tenth

end)

--十位0、2-9if(

@i=1and

@billion

>

0and

(@million

>0or

@thousand

>0or

@hundreds

>

0)) or(

@i=2and

(@billion

>0or

@million

>0)

and(

@thousand

>0or

@hundreds

>

0)) or(

@i=3and

(@billion

>0or

@million

>0or

@thousand

>0)

and(

@hundreds

>0))

set@result

=@result+'

, '--百位不是0則每段之間加連線符,if(

@i=3and

(@billion

>0or

@million

>0or

@thousand

>0)

and(

@hundreds=0

and(

@tenth

>0or

@one

>

0)))

set@result

=@result+'

and '--

百位是0則加連線符and

if@hundreds

>

0set

@result

=@result

+rtrim

(substring

(@numbers

,@hundreds*10

-9,10

))+'hundred'if

@tenth

>=

2and

@tenth

<=

9begin

if@hundreds

>

0set

@result

=@result+'

and

'set

@result

=@result

+rtrim

(substring

(@numbers

,@tenth*10

+171,10

))end

if@one

>=

1and

@one

<=

19begin

if@tenth

>

0set

@result

=@result+'

-'else

if@hundreds

>

0set

@result

=@result+'

and

'set

@result

=@result

+rtrim

(substring

(@numbers

,@one*10

-9,10

))end

if@i=0

and@billion

>

0set

@result

=@result+'

billion'if

@i=1and

@million

>

0set

@result

=@result+'

million'if

@i=2and

@thousand

>

0set

@result

=@result+'

thousand

'set@i=

@i+1end

ifsubstring(@s

,14,2

)<>'00

'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+'

'+rtrim

(substring

(@numbers

,cast

(substring(@s

,15,1

) as

int)*10

-9,10

))end

return

(@result

)end

go--

查詢select

dbo.f_num_eng(

52.25)/*

--------------------------

fifty-two point two five

(1 行受影響)

*/

將漢語數字轉化為阿拉伯數字

1,例如 輸入 二百五十 輸出 250 輸入 一百三十八 輸出 138 1 python實現具體資訊如下 class solution object def chinesetoint self,strs if strs return none dicts strs strs.replace 零 li...

阿拉伯數字轉成漢字

做乙個中醫專案時後台返回是阿拉伯數字,專案需求是需要轉化為中文數字,記錄一下轉化方法,感覺要比那種switch.case.拓展性好一點。因為當時不會超過一千,所以就寫到了百位,其他需求可以自行更改一下。當然預設傳的是整數型別的。public class numbertochineseutil str...

阿拉伯數字轉中文

public class cnuppercaser 供分級轉化的陣列,因為各個例項都要使用所以設為靜態 private static final char series 建構函式,通過它將阿拉伯數字形式的字串傳入 param original public cnuppercaser string o...