29 Ekim 2013 Salı
RAKAMLARI YAZIYA DÖNÜŞTÜRME ÖRNEĞİ
T
Public Class Form1 ' 1-9 ve 10 - 90 arasi 10'un katlari Private Function EnumPara(sayi As Integer) As String Dim a100 As String() = "sıfır,bir,iki,üç,dört,beş,altı,yedi,sekiz,dokuz".Split(","c) Dim a101 As String() = "on,yirmi,otuz,kırk,elli,altmış,yetmiş,seksen,doksan".Split(","c) Return If(sayi < 10, a100(sayi), a101(sayi \ 10 - 1)) End Function Private Function ParaToString(miktar As Double) As String If miktar = 0 Then Return "sıfır" ElseIf miktar Mod Math.Pow(10, 2) = 0 AndAlso miktar < 1000 Then Return (If(miktar / Math.Pow(10, 2) = 1, "", EnumPara(CInt(Math.Truncate(miktar / Math.Pow(10, 2)))))) & "yüz" ElseIf miktar Mod Math.Pow(10, 3) = 0 AndAlso miktar < Math.Pow(10, 6) Then Return If((miktar / Math.Pow(10, 3) = 1), "", ParaToString(miktar / Math.Pow(10, 3)) & "bin ") ElseIf miktar Mod Math.Pow(10, 6) = 0 AndAlso miktar < Math.Pow(10, 9) Then Return ParaToString(miktar / Math.Pow(10, 6)) & "milyon " ElseIf miktar Mod Math.Pow(10, 9) = 0 AndAlso miktar < Math.Pow(10, 12) Then Return ParaToString(miktar / Math.Pow(10, 9)) & "milyar " ElseIf miktar Mod Math.Pow(10, 12) = 0 AndAlso miktar < Math.Pow(10, 15) Then Return ParaToString(miktar / Math.Pow(10, 12)) & "trilyon " ElseIf miktar Mod Math.Pow(10, 15) = 0 AndAlso miktar < Math.Pow(10, 18) Then Return ParaToString(miktar / Math.Pow(10, 15)) & "katrilyon " ElseIf miktar Mod Math.Pow(10, 18) = 0 AndAlso miktar < Math.Pow(10, 21) Then Return ParaToString(miktar / Math.Pow(10, 18)) & "kentilyon " ElseIf miktar Mod Math.Pow(10, 21) = 0 AndAlso miktar < Math.Pow(10, 24) Then Return ParaToString(miktar / Math.Pow(10, 21)) & "sekstilyon " ElseIf miktar Mod Math.Pow(10, 24) = 0 AndAlso miktar < Math.Pow(10, 27) Then Return ParaToString(miktar / Math.Pow(10, 21)) & "septilyon " ElseIf miktar Mod Math.Pow(10, 27) = 0 AndAlso miktar < Math.Pow(10, 30) Then Return ParaToString(miktar / Math.Pow(10, 21)) & "oktilyon " ElseIf miktar Mod Math.Pow(10, 30) = 0 AndAlso miktar < Math.Pow(10, 33) Then Return ParaToString(miktar / Math.Pow(10, 21)) & "nonilyon " ElseIf miktar Mod Math.Pow(10, 33) = 0 AndAlso miktar < Math.Pow(10, 36) Then Return ParaToString(miktar / Math.Pow(10, 21)) & "desilyon " ElseIf miktar < 10 Then Return EnumPara(CInt(Math.Truncate(miktar))) ElseIf miktar < 100 Then Return EnumPara(CInt(Math.Floor(miktar / 10) * 10)) & (If(miktar Mod 10 = 0, "", EnumPara(CInt(Math.Truncate(miktar)) Mod 10))) ElseIf miktar < Math.Pow(10, 3) Then Return (If(ParaToString(Math.Floor(miktar / 100)) = "bir", "", ParaToString(Math.Floor(miktar / 100)))) & "yüz" & ParaToString(miktar Mod 100) ElseIf miktar < Math.Pow(10, 6) Then Return (If(ParaToString(Math.Floor(miktar / Math.Pow(10, 3))) = "bir", "", ParaToString(Math.Floor(miktar / Math.Pow(10, 3))))) & "bin " & ParaToString(miktar Mod Math.Pow(10, 3)) ElseIf miktar < Math.Pow(10, 9) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 6))) & "milyon " & ParaToString(miktar Mod Math.Pow(10, 6)) ElseIf miktar < Math.Pow(10, 12) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 9))) & "milyar " & ParaToString(miktar Mod Math.Pow(10, 9)) ElseIf miktar < Math.Pow(10, 15) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 12))) & "trilyon " & ParaToString(miktar Mod Math.Pow(10, 12)) ElseIf miktar < Math.Pow(10, 18) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 15))) & "katrilyon " & ParaToString(miktar Mod Math.Pow(10, 15)) ElseIf miktar < Math.Pow(10, 21) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 18))) & "kentilyon " & ParaToString(miktar Mod Math.Pow(10, 18)) ElseIf miktar < Math.Pow(10, 24) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 21))) & "sekstilyon " & ParaToString(miktar Mod Math.Pow(10, 21)) ElseIf miktar < Math.Pow(10, 27) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 24))) & "septilyon " & ParaToString(miktar Mod Math.Pow(10, 21)) ElseIf miktar < Math.Pow(10, 30) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 27))) & "oktilyon " & ParaToString(miktar Mod Math.Pow(10, 21)) ElseIf miktar < Math.Pow(10, 33) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 30))) & "nonilyon " & ParaToString(miktar Mod Math.Pow(10, 21)) ElseIf miktar < Math.Pow(10, 36) Then Return ParaToString(Math.Floor(miktar / Math.Pow(10, 33))) & "desilyon " & ParaToString(miktar Mod Math.Pow(10, 21)) Else Return "Ooooppss." End If End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click TextBox1.Text = ParaToString(TextBox2.Text) End Sub Private Sub TextBox2_LostFocus(sender As Object, e As System.EventArgs) Handles TextBox2.LostFocus Dim d As Double = CULng(TextBox2.Text.ToString) '1234567890 TextBox2.Text = d.ToString("N0") '1.234.567.890 End Sub 'Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '4 basamaklı sayılar için uygundur ' 'Me.Text = YaziIle(9845) ' TextBox1.Text = YaziIle(TextBox2.Text) 'End Sub 'Public Shared Function YaziIle(ByVal Sayi As Integer) As String ' Dim kelimeler(,) As String = {{"", "bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz", "dokuz"}, _ ' {"", "on", "yirmi", "otuz", "kırk", "elli", "altmış", "yetmiş", "seksen", "doksan"}, _ ' {"", "yüz", "ikiyüz", "üçyüz", "dörtyüz", "beşyüz", "altıyüz", "yediyüz", "sekizyüz", "dokuzyüz"}, _ ' {"", "bin", "ikibin", "üçbin", "dörtbin", "beşbin", "altıbin", "yedibin", "sekizbin", "dokuzbin"}} ' Return String.Join(" ", Sayi.ToString().Reverse().Select(Function(f As Char, c As Integer) kelimeler(c, Integer.Parse(f)).ToString).Reverse.ToArray) 'End Function Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load TextBox2.Focus() End Sub End Class
Hiç yorum yok:
Yorum Gönder
Sonraki Kayıt
Önceki Kayıt
Ana Sayfa
Kaydol:
Kayıt Yorumları (Atom)
Hiç yorum yok:
Yorum Gönder