1. ホーム
  2. Web プログラミング
  3. ASP プログラミング
  4. アプリケーションのヒント

数字を漢数字(大文字の金額)に変換するASP機能

2022-01-18 08:46:53

以下に、この関数を実装する2種類の方法を紹介します。

数字を漢数字に変換するASP関数

<% 
function Money(thenumber)
'dim Money,i,String1,String2,length,checkp' define variables
dim one(),onestr()'define array
 
String1 = "zero one,two,three,four,five,seven,eight,nine"

 
checkp=instr(thenumber,". ")'determine if it contains decimal places
if checkp<>0 then
 thenumber=replace(thenumber,". ","")'Remove decimal places
end if
length=len(thenumber) 'get the length of the data
redim one(length-1) 'redefine the size of the array
redim onestr(length-1)'redefine the size of the array
for i=0 to length-1
 one(i)=mid(thenumber,i+1,1) 'loop to get the number of each bit
 one(i)=mid(string1,one(i)+1,1) 'loop to get the number corresponding to the upper case
 if checkp=0 then 'the data that does not contain a decimal whose number corresponds to the unit
  onestr(i)=mid(string2,14-length+i,1)
 else 'the data containing decimals and the units corresponding to their numbers
  onestr(i)=mid(string2,15-length+i+len(thenumber)-checkp,1)
 end if
 one(i)=one(i)&onestr(i)'Combine numbers and units
 next
  Money=replace(join(one)," ","") 'get all the elements of the array and join
  Money=replace(Money,"zero dollars","dollars")
  Money=replace(Money,"zero million","million")
  Money=replace(Money,"zero billion","billion")
  Money=replace(Money,"零千","零")
  Money=replace(Money,"零百","零")
  Money=replace(Money,"零拾","零")
 
 do while not instr(Money,"zero")=0
 Money=replace(Money,"零零","零")
 loop
 
' response.write Money 'Show results
 end function
Response.write Money(8200001)
%>

ASPアラビア数字から漢数字へ

<% 
'################################ 
'Function name: Arabic to Chinese numeric function 
'################################ 
function chnumstr(num) 
num=int(abs(num))
strlen=len(num) 
for i=1 to strlen 
select case mid(num,i,1) 
case 1:chnum="one":case 2:chnum="two":case 3:chnum="three"
case 4:chnum="four":case 5:chnum="five" 
case 6:chnum="six":case 7:chnum="seven":case 8:chnum="eight"
case 9:chnum="nine":case 0:chnum="zero" 
end select 
chnumstr=chnumstr&chnum 
if i=strlen-1 and mid(num,i,1)<>0 then chnumstr=chnumstr&"ten" 
if i=strlen-2 and mid(num,i,1)<>0 then chnumstr=chnumstr&"hundred" 
if i=strlen-3 and mid(num,i,1)<>0 then chnumstr=chnumstr&"thousand" 
if i=strlen-4 and mid(num,i,1)<>0 then chnumstr=chnumstr&"thousands" 
if i=strlen-5 and mid(num,i,1)<>0 then chnumstr=chnumstr&"ten" 
if i=strlen-6 and mid(num,i,1)<>0 then chnumstr=chnumstr&"hundred" 
if i=strlen-7 and mid(num,i,1)<>0 then chnumstr=chnumstr&"thousand" 
if i=strlen-8 and mid(num,i,1)<>0 then chnumstr=chnumstr&"thousands" 
next 
if left(chnumstr,1)="one" then chnumstr=right(chnumstr,len(chnumstr)-1)
if right(chnumstr,1)="zero" then chnumstr=left(chnumstr,len(chnumstr)-1)
end function
Response.write chnumstr("84221213")
%>

数字を漢数字(大文字)に変換するASP機能についてはこの記事が全てです、もっと関連するASP数字を漢数字に変換する内容はBinaryDevelopの過去記事を検索するか、以下の関連記事を引き続き閲覧してください、今後ともBinaryDevelopを応援していただけると幸いです