Hàm này viết bằng VB.NET, cần chuyển sang ngôn ngữ khác thì vào đây
http://www.developerfusion.com/tools/convert/csharp-to-vb/
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | Function docso(ByVal number As Decimal) As String         Dim str As String = ""         Dim s As String = number.ToString()         Dim so() As String = {"không", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín"}         Dim hang() As String = {"", "ngàn", "triệu", "tỉ"}         Dim i, j, donvi, chuc, tram As Integer         Dim booAm As Boolean = False         Dim decS As Decimal = 0         Try             decS = Convert.ToDecimal(s.ToString())         Catch ex As Exception         End Try         If (decS < 0) Then             decS = -decS             s = decS.ToString()             booAm = True         End If         i = s.Length 'chiều dài dãy số         If (i = 0) Then             str = so(0) & str         Else             j = 0             While (i > 0)                 donvi = Convert.ToInt32(s.Substring(i - 1, 1))                 i -= 1                 If (i > 0) Then                     chuc = Convert.ToInt32(s.Substring(i - 1, 1))                 Else                     chuc = -1                 End If                 i -= 1                 If (i > 0) Then                     tram = Convert.ToInt32(s.Substring(i - 1, 1))                 Else                     tram = -1                 End If                 i -= 1                 If ((donvi > 0) Or (chuc > 0) Or (tram > 0) Or (j = 3)) Then                     str = hang(j) & str                 End If                 j += 1                 If (j > 3) Then                     j = 1                 End If                 If ((donvi = 1) And (chuc > 1)) Then                     str = "một " & str                 Else                     If ((donvi = 5) And (chuc > 0)) Then                         str = "lăm " & str                     ElseIf (donvi > 0) Then                         str = so(donvi) & " " & str                     End If                 End If                 If (chuc < 0) Then                     Continue While                 Else                     If ((chuc = 0) And (donvi > 0)) Then                         str = "lẻ " & str                     End If                     If (chuc = 1) Then                         str = "mười " & str                     End If                     If (chuc > 1) Then                         str = so(chuc) & " mươi " & str                     End If                 End If                 If (tram < 0) Then                     Exit While                 Else                     If ((tram > 0) Or (chuc > 0) Or (donvi > 0)) Then                         str = so(tram) & " trăm " & str                     End If                 End If                 str = " " & str             End While         End If         If booAm = True Then             str = "Âm " & str         End If         str = StrConv(str(0), VbStrConv.Uppercase) & str.Substring(1, str.Length - 1) & "đồng"         Return str     End Function |