Skip to content

Instantly share code, notes, and snippets.

@aysegulsarikaya
Created March 28, 2019 19:39
Show Gist options
  • Select an option

  • Save aysegulsarikaya/263d933623ab6a80ba19d878acc88b32 to your computer and use it in GitHub Desktop.

Select an option

Save aysegulsarikaya/263d933623ab6a80ba19d878acc88b32 to your computer and use it in GitHub Desktop.
private void btnCevir_Click(object sender, EventArgs e)
{
lblYazi.Text = Yaziyla(Convert.ToDouble(txtNumber.Text));
}
static string frNumToStr2(Double Sayi)
{
string[] birler = { "", "BİR", "İKİ", "ÜÇ", "DÖRT", "BEŞ", "ALTI", "YEDİ", "SEKİZ", "DOKUZ" };
string[] onlar = { "", "ON", "YİRMİ", "OTUZ", "KIRK", "ELLİ", "ALTMIŞ", "YETMİŞ", "SEKSEN", "DOKSAN" };
string[] katlar = {"", "YÜZ", "BİN", "MİLYON", "MİLYAR", "TRİLYON", "KATRİLYON" };
string rakam = "";
double bolum, sonuc, b;
for (int Kat = 6; Kat > 0; Kat--)
{
bolum = (int)(Sayi / Math.Pow(1000, Kat - 1));
b = bolum;
if (bolum != 0)
{
if (bolum > 199)
{
sonuc = (int)(bolum / 100);
rakam = rakam + birler[(int)(Math.Truncate(sonuc))];
bolum = bolum - sonuc * 100;
rakam = rakam + katlar[1];
}
if ((bolum > 99) && (bolum <= 199))
{
rakam = rakam + katlar[1];
bolum = bolum - 100;
}
if ((bolum > 9) && (bolum <= 99))
{
sonuc = (int)(bolum / 10);
rakam = rakam + onlar[(int)(Math.Truncate(sonuc))];
bolum = (int)(bolum - sonuc * 10);
}
if ((bolum > 0) && (bolum <= 9))
if ((Sayi > 1999) || (Sayi < 1000))
rakam = rakam + birler[(int)(Math.Truncate(bolum))];
if (Kat != 1)
rakam = rakam + katlar[Kat] + " "; // 5-4-3-2-1
Sayi = Sayi - (b * Math.Pow(1000, Kat - 1));
}
}
return rakam;
}
static string Yaziyla(double Deger)
{
int tamkisim;
int kuruskisim;
string tamstr, kurusstr;
tamkisim = (int)Math.Truncate(Deger);
kuruskisim = (int)Math.Truncate((Deger - tamkisim) * 10000) / 100;
if (kuruskisim < 1) kurusstr = "SIFIR"; else kurusstr = frNumToStr2(kuruskisim);
if (tamkisim < 1) tamstr = "SIFIR"; else tamstr = frNumToStr2(tamkisim);
return $"{tamstr} TL {kurusstr} KURUŞ";
}
private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) && e.KeyChar != '.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment