如果有这种现成的算法,最好提供一下,分数好说!

解决方案 »

  1.   

    Public lngNum As Long
    Public intLen, intPos, intCur, intWei, flag As Integer
    Public strScr, strNum As String
    Public ComPhone, ComAdress, ComFax, ComName As String
    Public Sub sTeen()
        Select Case intCur
            Case 1: strScr = "ten"
            Case 2: strScr = "twenty"
            Case 3: strScr = "thirty"
            Case 4: strScr = "forty"
            Case 5: strScr = "fifty"
            Case 6: strScr = "sixty"
            Case 7: strScr = "seventy"
            Case 8: strScr = "eighty"
            Case 9: strScr = "ninty"
        End Select
        strNum = strScr & " " & strNum
    End Sub
    Public Sub sSimp()
        Select Case intCur
            Case 1: strScr = "one"
            Case 2: strScr = "two"
            Case 3: strScr = "three"
            Case 4: strScr = "four"
            Case 5: strScr = "five"
            Case 6: strScr = "six"
            Case 7: strScr = "seven"
            Case 8: strScr = "eight"
            Case 9: strScr = "nine"
        End Select
        strNum = strScr & " " & strNum
    End Sub
    Public Sub sSpec()
        Select Case intCur
            Case 11: strScr = "eleven"
            Case 12: strScr = "twelve"
            Case 13: strScr = "thirteen"
            Case 14: strScr = "fourteen"
            Case 15: strScr = "fifteen"
            Case 16: strScr = "sixteen"
            Case 17: strScr = "seventeen"
            Case 18: strScr = "eighteen"
            Case 19: strScr = "nineteen"
        End Select
        strNum = strScr & " " & strNum
    End Sub
    Public Sub sTrans()
        flag = 0
        Select Case intWei
            Case 2: strNum = "thousand " & strNum
            Case 3: strNum = "million " & strNum
            Case 4: strNum = "billion " & strNum
        End Select
        intCur = intPos Mod 10
        If intCur <> 0 Then '处理个位
            If intPos Mod 100 - intPos Mod 10 = 10 Then
                intCur = intPos Mod 100
                Call sSpec '11-19
            Else
                Call sSimp '1-9
            End If
            flag = 1
        End If
        
        If intCur < 10 Then
            intCur = (intPos Mod 100 - intPos Mod 10) / 10
        Else
            intCur = 0
        End If
        If intCur <> 0 Then
            If flag = 1 Then
                strNum = Trim(strNum)
            End If
            Call sTeen '10-90
            flag = 1
        End If
        intCur = Int(intPos / 100)
        If intCur <> 0 Then
            If flag = 1 Then
                strNum = "and " & strNum
            End If
            strNum = "hundred " & strNum
            Call sSimp
        End If
    End Sub
    Private Sub Command1_Click()
        isMove = True
        intWei = 0
        strNum = ""
        If IsNumeric(txt1.Text) Then
            lngNum = CLng(txt1.Text)
            intLen = Len(txt1.Text)
            Do While intLen > 0
                intPos = lngNum Mod 1000
                intLen = intLen - 3
                lngNum = (lngNum - intPos) / 1000
                intWei = intWei + 1
                Call sTrans
            Loop
            txt2.text = strNum 
        End If
    end sub
    txt1.text里面是你的数字
    txt2.text是你要的结果
      

  2.   

    Private Function t(ByVal numint As Long) As String
       Dim tempInt As String
       Dim s As String
       Dim s1, s2, s3 As String
       s = CStr(numint)
       tempInt = Len(s)
       If tempInt > 10 Then MsgBox "最大可以处理9位"
       
       If tempInt < 10 And tempInt > 7 Then
          s1 = play(CInt(Mid(CStr(numint), 1, 3))) & "million "
          s2 = play(CInt(Mid(CStr(numint), 4, 3))) & "thousand "
          s3 = play(CInt(Right(CStr(numint), 3)))
       End If
          
       If tempInt < 7 Then
          s1 = play(CInt(Mid(CStr(numint), 1, 3))) & " thousand "
          s2 = play(CInt(Mid(CStr(numint), 4, 3)))
       End If
     
       If tempInt < 4 Then
           s1 = play(CInt(Mid(CStr(numint), 1, 3)))
       End If
       
       t = s1 & s2 & s3
       Text2.Text = t
    End FunctionFunction play(ByVal numint As Integer) As String
         Dim s, s1, s2 As String
         s = CStr(numint)
          s = Mid(s, 1, 1)
          If s = "1" Then
             s1 = "one hundred "
          ElseIf s = "2" Then
             s1 = "tow hundred "
          ElseIf s = "3" Then
             s1 = "three hundred "
          ElseIf s = "4" Then
             s1 = "four hundred "
          ElseIf s = "5" Then
             s1 = "five hundred "
          ElseIf s = "6" Then
             s1 = "six hundred "
          ElseIf s = "7" Then
             s1 = "seven hundred "
          ElseIf s = "8" Then
             s1 = "eight hundred "
          ElseIf s = "9" Then
             s1 = "nine hundred "
          End If
         s2 = s1
         s = Mid(CStr(numint), 2, 1)
         If s = "1" Then
             s = Mid(CStr(numint), 2, 2)
             If s = "10" Then
                s1 = "and ten"
             ElseIf s = "11" Then
                s1 = "and eleven"
             ElseIf s = "12" Then
                s1 = "and twelve"
             ElseIf s = "13" Then
                s1 = "and thirteen"
             ElseIf s = "14" Then
                s1 = "and fourteen "
             ElseIf s = "15" Then
                s1 = "and fifteen"
             ElseIf s = "16" Then
                s1 = "and sixteen"
             ElseIf s = "17" Then
                s1 = "and seventeen"
             ElseIf s = "18" Then
                s1 = "and eighteen"
             ElseIf s = "19" Then
                s1 = "and nineteen"
              End If
          ElseIf s = "2" Then
             s1 = "and twenty"
          ElseIf s = "3" Then
             s1 = "and thirty"
          ElseIf s = "4" Then
             s1 = "and forty"
          ElseIf s = "5" Then
             s1 = "and fifty"
          ElseIf s = "6" Then
             s1 = "and sixty"
          ElseIf s = "7" Then
             s1 = "and seventy"
          ElseIf s = "8" Then
             s1 = "and eighty"
          ElseIf s = "9" Then
             s1 = "and ninety"
          End If
          
          s2 = s2 + s1
          s = Mid(CStr(numint), 3, 1)
          If s = "1" Then
             s1 = " one  "
          ElseIf s = "2" Then
             s1 = " tow  "
          ElseIf s = "3" Then
            s1 = " three   "
          ElseIf s = "4" Then
            s1 = " four  "
          ElseIf s = "5" Then
             s1 = " five  "
          ElseIf s = "6" Then
             s1 = " six  "
          ElseIf s = "7" Then
            s1 = " seven "
          ElseIf s = "8" Then
             s1 = " eight  "
          ElseIf s = "9" Then
             s1 = " nine  "
          End If
          s2 = s2 + s1
          play = s2
    End Functiont是你要的结果
      

  3.   

    前面那两位仁兄的算法有点问题。例如:英语中空位是要加“and”的。就像 1002 应该读作:“one thousand and two”;而您的程序却会显示:“one thousand two”等等。我写的这个算法应该没有错了。有几点说明一下,我使用的是美式读法,1 billion = 1,000 million,在读小数时,两位小数以内用两位数的读法,如 9.15 读作“nine point fifteen”;三位小数或以上时逐位读出,小数中的零读作字母“O”,如 2.305 读作“two point three o five”;没有整数部分时,不加 zero,如 0.5 读作“point five”。使用时调用函数 Convert 就可以了(其它的是我内部使用),参数就是要转换的数字,返回值是转换完成的结果。我的这个算法只支持到 hundred billion 位,即 999,999,999,999。溢出会返回 vbNullString。
    本程序支持负数。如果你还有什么别的要求,我乐意帮你修改。举个例子,如:Dim result As String
    result = Convert(-12034.506)执行后 result 的值为:minus twelve thousand and thirty-four point five o six如果有错误,请告知[email protected],谢谢!
      

  4.   

    VERSION 1.0 CLASS
    BEGIN
      MultiUse = -1  'True
      Persistable = 0  'NotPersistable
      DataBindingBehavior = 0  'vbNone
      DataSourceBehavior  = 0  'vbNone
      MTSTransactionMode  = 0  'NotAnMTSObject
    END
    Attribute VB_Name = "NumConvert"
    Attribute VB_GlobalNameSpace = True
    Attribute VB_Creatable = True
    Attribute VB_PredeclaredId = False
    Attribute VB_Exposed = True
    Option Explicit' ==================================
    '
    ' Convert 函数: 将数字转换成美式英语读法
    ' 制作: 2003年,包善东
    '
    ' 入口参数:
    '         N - 要转换的数字
    '
    ' 返回值:
    '         转换完成的字符串
    '
    ' ==================================
    Public Function Convert(ByVal N As Double) As String
        Dim i As Long
        Dim strN As String, strNint As String, strNflt As String
        Dim Minus As Boolean
        Dim Seg As Byte
        Dim SegNum(0 To 3) As String
        Dim SegDesc(0 To 3) As String
        Dim SegBlank(0 To 3) As Boolean
        Dim SegFloat As String
        Dim BlankFlag As Boolean
        
        ' 判断符号
        If N = 0 Then
            ' 为零
            Convert = "zero"
            Exit Function
        ElseIf N > 0 Then
            ' 正数
            Minus = False
        Else
            ' 负数
            Minus = True
        End If
        strN = CStr(Abs(N))
        
        ' 定位小数点
        i = InStr(1, strN, ".")
        If i = 0 Then
            strNint = strN
            strNflt = ""
        Else
            strNint = Left(strN, i - 1)
            strNflt = Mid(strN, i + 1)
        End If
        
        ' =====================
        ' 处理符号部分
        ' =====================    Convert = IIf(Minus = True, "minus ", "")
        
        ' =====================
        ' 处理整数部分
        ' =====================
        
        ' 超过 hundred billion 一级(即 12 位)则返回错误
        If Len(strN) > 12 Then
            Convert = vbNullString  ' 这里也可以换作 "#error" 等消息
            Exit Function
        End If
        
        ' 按三位一段计算段数
        Seg = Len(strNint) \ 3 + IIf(Len(strNint) Mod 3 = 0, 0, 1)
        
        ' 转换每段
        For i = 0 To Seg - 1
            ' 取最右 3 位分段
            If Len(strNint) > 3 Then
                ' 如果超过 3 位,则取右 3 位
                SegNum(i) = Right(strNint, 3)
                ' 去掉已分段的数字
                strNint = Left(strNint, Len(strNint) - 3)
            Else
                ' 不足则取全部
                SegNum(i) = strNint
            End If
        
            ' 转换段
            SegDesc(i) = ConvertSeg(SegNum(i), SegBlank(i))
        Next
        
        ' 合并各段文字
        BlankFlag = False
        For i = Seg - 1 To 0 Step -1        ' 从高位开始
            ' 处理本段空段标志
            If SegBlank(i) = True And i <> Seg - 1 Then
                If BlankFlag = False Then
                    ' 如果前面不是空段就加 and
                    Convert = Convert & "and "
                    BlankFlag = True
                End If
            Else
                BlankFlag = False
            End If
            
            ' 将本段文字加上单位并入
            If SegDesc(i) <> "" Then
                Convert = Convert & SegDesc(i) & " " & ConvertBit("SEG" & CStr(i)) & " "
            End If
        Next
        
        ' 除去多余的空格
        Convert = Trim(Convert)
        
        ' =====================
        ' 处理小数部分
        ' =====================
        
        If Len(strNflt) <= 2 Then
            ' 两位之内按十位数方法读
            SegFloat = ConvertSeg(strNflt)
        Else
            ' 三位及以上逐位读出
            SegFloat = ""
            For i = 1 To Len(strNflt)
                If Mid(strNflt, i, 1) = "0" Then
                    ' 零读成字母 O
                    SegFloat = SegFloat & "o "
                Else
                    ' 逐位读出
                    SegFloat = SegFloat & ConvertBit(Mid(strNflt, i, 1)) & " "
                End If
            Next
        End If
        
        ' 如果有小数部分则添上
        If SegFloat <> "" Then
            Convert = Convert & " point " & SegFloat
        End If
        Convert = Trim(Convert)
    End Function' 转换一个三位数(即一个段)
    Private Function ConvertSeg(ByVal N As String, Optional ByRef BK As Boolean) As String
        Dim buf As String
        Dim buf1 As String, buf2 As String
        
        ' 补足三位
        buf = ""
        If Len(N) < 3 Then
            N = String(3 - Len(N), "0") & N
        End If
        
        ' 转换百位
        If Left(N, 1) <> "0" Then
            buf1 = ConvertBit(Mid(N, 1, 1))
        Else
            buf1 = ""
        End If
        
        ' 转换十、个位
        If Val(Right(N, 2)) <= 20 Then
            ' 小于 20 特殊处理
            buf2 = ConvertBit(Right(N, 2))
        Else
            ' 转换十位
            buf2 = ConvertBit(Mid(N, 2, 1) & "0")
            ' 转换个位
            If Right(N, 1) <> "0" Then
                buf2 = buf2 & "-" & ConvertBit(Right(N, 1))
            End If
        End If
        
        ' 组合各位
        If buf1 = "" Then
            ' 没有百位
            buf = buf2
            BK = True
        Else
            ' 有百位
            BK = False
            If buf2 = "" Then
                ' 没有十位与个位
                buf = buf1 & " " & ConvertBit("h")
            Else
                ' 有十位或个位
                buf = buf1 & " " & ConvertBit("h") & " and " & buf2
            End If
        End If
        
        ConvertSeg = buf
    End Function' 单个单词的转换
    Private Function ConvertBit(ByVal N As String) As String
        If IsNumeric(N) = True Then
            ' 除去数字前多余的零
            N = CStr(Val(N))
        End If
        Select Case N
            Case "0":           ConvertBit = ""
            Case "1":           ConvertBit = "one"
            Case "2":           ConvertBit = "two"
            Case "3":           ConvertBit = "three"
            Case "4":           ConvertBit = "four"
            Case "5":           ConvertBit = "five"
            Case "6":           ConvertBit = "six"
            Case "7":           ConvertBit = "seven"
            Case "8":           ConvertBit = "eight"
            Case "9":           ConvertBit = "nine"
            Case "10":          ConvertBit = "ten"
            Case "11":          ConvertBit = "eleven"
            Case "12":          ConvertBit = "twelve"
            Case "13":          ConvertBit = "thirteen"
            Case "14":          ConvertBit = "fourteen"
            Case "15":          ConvertBit = "fifteen"
            Case "16":          ConvertBit = "sixteen"
            Case "17":          ConvertBit = "seventeen"
            Case "18":          ConvertBit = "eighteen"
            Case "19":          ConvertBit = "nineteen"
            Case "20":          ConvertBit = "twenty"
            Case "30":          ConvertBit = "thirty"
            Case "40":          ConvertBit = "forty"
            Case "50":          ConvertBit = "fifty"
            Case "60":          ConvertBit = "sixty"
            Case "70":          ConvertBit = "seventy"
            Case "80":          ConvertBit = "eighty"
            Case "90":          ConvertBit = "ninety"
            Case "SEG0":        ConvertBit = ""
            Case "h":           ConvertBit = "hundred"
            Case "SEG1":        ConvertBit = "thousand"
            Case "SEG2":        ConvertBit = "million"
            Case "SEG3":        ConvertBit = "billion"
            Case Else:          ConvertBit = vbNullString
        End Select
    End Function
      

  5.   

    哎呀,我是说,你在读像 1002 之类的数字时没有 and。
      

  6.   

    不好意思,我发现自己的程序有一个问题,把处理小数部分那一段换成下面的代码(改动在第一行):    ' =====================
        ' 处理小数部分
        ' =====================
        
        If Len(strNflt) <= 2 And Left(strNflt, 1) <> "0" Then
            ' 两位之内且首位不为零时按十位数方法读
            SegFloat = ConvertSeg(strNflt)
        Else
            ' 三位及以上逐位读出
            SegFloat = ""
            For i = 1 To Len(strNflt)
                If Mid(strNflt, i, 1) = "0" Then
                    ' 零读成字母 O
                    SegFloat = SegFloat & "o "
                Else
                    ' 逐位读出
                    SegFloat = SegFloat & ConvertBit(Mid(strNflt, i, 1)) & " "
                End If
            Next
        End If