fung asked in 電腦與網際網路程式設計 · 2 decades ago

# 數字轉英文

e.g. 1234.56 -> one thousand and two hundred thirty four and cents fifty six only

### 2 Answers

Rating
• Anonymous
2 decades ago
Favorite Answer

用程式寫?

請多一點描述

2005-06-26 00:49:03 補充：

Private Sub Command1_Click()

Dim S, Te, U As String

Dim a, b, x, SL As Integer

S = Text1.Text

x = InStr(1, S, ".")

SL = Len(S)

If x <> 0 Then

a = Val(Mid(S, 1, x - 1))

b = Val(Mid(S, x + 1, SL - x))

Else

a = Val(Mid(S, 1, SL))

b = 0

End If

U = ""

If a < 1000 Then

If a < 100 Then

If a < 21 Then

Te = SS(a)

ElseIf a >= 21 Then

Te = SS(Int(a / 10) * 10) & SS(a Mod 10)

End If

ElseIf a >= 100 Then

Te = SS(Int(a / 100)) & "Huntred " & SS(Int((a Mod 100) / 10) * 10) & SS(a Mod 10)

End If

ElseIf a >= 1000 And a < 21000 Then

Te = SS(Int(a / 1000)) & "Thousand " & SS(Int((a Mod 1000) / 100)) & "Huntred " & SS(Int((a Mod 100) / 10) * 10) & SS(a Mod 10)

ElseIf a >= 21000 Then

Te = SS(Int(a / 10000) * 10) & SS(Int((a Mod 10000) / 1000)) & "Thousand " & SS(Int((a Mod 1000) / 100)) & "Huntred " & SS(Int((a Mod 100) / 10) * 10) & SS(a Mod 10)

End If

U = U & " " & Te

If b > 0 And b < 21 Then

U = U & "And " & SS(b) & " Cents"

ElseIf b >= 21 Then

U = U & "And " & SS(Int(b / 10) * 10) & SS(b Mod 10) & " Cents"

End If

Text2.Text = U

End Sub

Function SS(ByVal T As Integer)

Dim Te As String

Select Case T

Case 1

Te = "One "

Case 2

Te = "Two "

Case 3

Te = "Three "

Case 4

Te = "Four "

Case 5

Te = "Five "

Case 6

Te = "Six "

Case 7

Te = "Seven "

Case 8

Te = "Eight "

Case 9

Te = "Nine "

Case 10

Te = "Ten "

Case 11

Te = "Eleven "

Case 12

Te = "Twelve "

Case 13

Te = "Thirteen "

Case 14

Te = "Fourteen "

Case 15

Te = "Fifteen "

Case 16

Te = "Sixteen "

Case 17

Te = "Seventeen "

Case 18

Te = "Eighteen "

Case 19

Te = "Nineteen "

Case 20

Te = "Twenty "

Case 30

Te = "Thirty "

Case 40

Te = "Forty "

Case 50

Te = "Fifty "

Case 60

Te = "Sixty "

Case 70

Te = "Seventy "

Case 80

Te = "Eighty "

Case 90

Te = "Ninety "

End Select

SS = Te

End Function

'數字轉英文,先做最大到100000的,其他依此類推....

'先拉兩個textbox , ㄧ個 Commandbutton

Source(s): Me (by VB 6.0)
• Anonymous
2 decades ago

你想描述什麼? 這個都算經典問題,還要問什麼呢?

可惜我不願做這類麻煩的題目... 給你一點提示 :

先把1至10,20,30..90,100,1000,1000000...直到輸入的上限為止

所需的英文字存起作為constant (final)

然後你需要清楚由數字轉英文的規則, 把他們列出來

最後做分類, 畫個流程圖出來才開始寫程式

Still have questions? Get your answers by asking now.