Created
September 1, 2024 13:18
-
-
Save mcihad/b145bce5801e06b93e9f2f140aaa110c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NumberExtension | |
{ | |
static string[] birler = { "", "Bir", "İki", "Üç", "Dört", "Beş", "Altı", "Yedi", "Sekiz", "Dokuz" }; | |
static string[] onlar = { "", "On", "Yirmi", "Otuz", "Kırk", "Elli", "Altmış", "Yetmiş", "Seksen", "Doksan" }; | |
static string[] gruplar = { "", "Bin", "Milyon", "Milyar", "Trilyon", "Katrilyon" }; | |
public static String Humanize(this long sayi) | |
{ | |
if (sayi == 0) | |
return "Sıfır"; | |
string cevirilen = ""; | |
int grupIndeksi = 0; | |
while (sayi > 0) | |
{ | |
int grupDegeri = (int)(sayi % 1000); | |
if (grupDegeri > 0) | |
{ | |
string grupDegeriYaziyla = GrupDegeriniCevir(grupDegeri, grupIndeksi == 1); | |
cevirilen = grupDegeriYaziyla + " " + gruplar[grupIndeksi] + " " + cevirilen; | |
} | |
sayi /= 1000; | |
grupIndeksi++; | |
} | |
return cevirilen.Trim(); | |
} | |
static string GrupDegeriniCevir(int sayi, bool binlikGrubu) | |
{ | |
int yuzler = sayi / 100; | |
int onlarBasamagi = (sayi % 100) / 10; | |
int birlerBasamagi = sayi % 10; | |
string yaziyla = ""; | |
if (yuzler > 0) | |
{ | |
if (yuzler == 1) | |
yaziyla += "Yüz "; | |
else | |
yaziyla += birler[yuzler] + " Yüz "; | |
} | |
if (onlarBasamagi > 0) | |
yaziyla += onlar[onlarBasamagi] + " "; | |
if (birlerBasamagi > 0) | |
{ | |
if (binlikGrubu && birlerBasamagi == 1) | |
yaziyla += ""; | |
else | |
yaziyla += birler[birlerBasamagi] + " "; | |
} | |
return yaziyla; | |
} | |
static string KurusuCevir(long kurus) | |
{ | |
string kurusYaziyla = kurus.Humanize(); | |
if (kurus == 0) | |
return ""; | |
if (kurusYaziyla == "Bir") | |
kurusYaziyla = "Bir Kuruş"; | |
else | |
kurusYaziyla += " Kuruş"; | |
return kurusYaziyla; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment