locked
convert number to word RRS feed

  • Question

  • User66371569 posted
    I have one textbox contain number

    forexample 3,30977,12
    I want to convert it in word
    3
    Sunday, March 3, 2019 3:36 PM

All replies

  • User61956409 posted

    Hi thepast,

    I have one textbox contain number

    forexample 3,30977,12
    I want to convert it in word
    3

    Please clarify more about your question, so that we can understand it better and help you achieve the requirement. 

    Besides, if you'd like to split the "3,30977,12" by ",", and then get the min value from it, you can refer to the following code snippet.

    Dim text_num As String = TextBox1.Text
    Dim res As Int32 = Convert.ToInt32(text_num.Split(",")(0))
    
    For index = 1 To text_num.Split(",").Length - 1
        If Convert.ToInt32(text_num.Split(",")(index)) < res Then
            res = Convert.ToInt32(text_num.Split(",")(index))
        End If
    Next

    With Regards,

    Fei Han

    Monday, March 4, 2019 2:08 AM
  • User66371569 posted
    no not like this

    i want conver numbers in word

    100 One thousend
    Monday, March 4, 2019 7:38 AM
  • User61956409 posted

    Hi thepast,

    i want conver numbers in word

    To convert numeric value to words, you can refer to this article.

    https://www.c-sharpcorner.com/article/convert-numeric-value-into-words-currency-in-c-sharp/ 

    Besides, if you'd like to achieve it in VB, you can refer to the following code snippet.

    Private Shared Function ones(ByVal Number As String) As String
        Dim _Number As Integer = Convert.ToInt32(Number)
        Dim name As String = ""
    
        Select Case _Number
            Case 1
                name = "One"
            Case 2
                name = "Two"
            Case 3
                name = "Three"
            Case 4
                name = "Four"
            Case 5
                name = "Five"
            Case 6
                name = "Six"
            Case 7
                name = "Seven"
            Case 8
                name = "Eight"
            Case 9
                name = "Nine"
        End Select
    
        Return name
    End Function
    
    Private Shared Function tens(ByVal Number As String) As String
        Dim _Number As Integer = Convert.ToInt32(Number)
        Dim name As String = Nothing
    
        Select Case _Number
            Case 10
                name = "Ten"
            Case 11
                name = "Eleven"
            Case 12
                name = "Twelve"
            Case 13
                name = "Thirteen"
            Case 14
                name = "Fourteen"
            Case 15
                name = "Fifteen"
            Case 16
                name = "Sixteen"
            Case 17
                name = "Seventeen"
            Case 18
                name = "Eighteen"
            Case 19
                name = "Nineteen"
            Case 20
                name = "Twenty"
            Case 30
                name = "Thirty"
            Case 40
                name = "Fourty"
            Case 50
                name = "Fifty"
            Case 60
                name = "Sixty"
            Case 70
                name = "Seventy"
            Case 80
                name = "Eighty"
            Case 90
                name = "Ninety"
            Case Else
    
                If _Number > 0 Then
                    name = tens(Number.Substring(0, 1) & "0") & " " + ones(Number.Substring(1))
                End If
        End Select
    
        Return name
    End Function
    
    Private Shared Function ConvertWholeNumber(ByVal Number As String) As String
        Dim word As String = ""
    
        Try
            Dim beginsZero As Boolean = False
            Dim isDone As Boolean = False
            Dim dblAmt As Double = (Convert.ToDouble(Number))
    
            If dblAmt > 0 Then
                beginsZero = Number.StartsWith("0")
                Dim numDigits As Integer = Number.Length
                Dim pos As Integer = 0
                Dim place As String = ""
    
                Select Case numDigits
                    Case 1
                        word = ones(Number)
                        isDone = True
                    Case 2
                        word = tens(Number)
                        isDone = True
                    Case 3
                        pos = (numDigits Mod 3) + 1
                        place = " Hundred "
                    Case 4, 5, 6
                        pos = (numDigits Mod 4) + 1
                        place = " Thousand "
                    Case 7, 8, 9
                        pos = (numDigits Mod 7) + 1
                        place = " Million "
                    Case 10, 11, 12
                        pos = (numDigits Mod 10) + 1
                        place = " Billion "
                    Case Else
                        isDone = True
                End Select
    
                If Not isDone Then
    
                    If Number.Substring(0, pos) <> "0" AndAlso Number.Substring(pos) <> "0" Then
    
                        Try
                            word = ConvertWholeNumber(Number.Substring(0, pos)) + place + ConvertWholeNumber(Number.Substring(pos))
                        Catch
                        End Try
                    Else
                        word = ConvertWholeNumber(Number.Substring(0, pos)) + ConvertWholeNumber(Number.Substring(pos))
                    End If
                End If
    
                If word.Trim().Equals(place.Trim()) Then word = ""
            End If
    
        Catch
        End Try
    
        Return word.Trim()
    End Function

    With Regards,

    Fei Han

    Monday, March 4, 2019 7:58 AM
  • User66371569 posted

    my number in textbox.text

    so how can apply code to convert this number exists in textbox 

    Tuesday, March 5, 2019 7:06 AM
  • User61956409 posted

    Hi thepast,

    my number in textbox.text

    so how can apply code to convert this number exists in textbox 

    You can access/get the value of TextBox control that user input from code behind, such as perform above convert operation in a button click event.

    Besides, you can also implement same convert functionality in web method or a backend service, and then you can call and passing the value of your TextBox control to that service from javascript cleint side using AJAX.

    With Regards,

    Fei Han

    Tuesday, March 5, 2019 8:25 AM