Skip to content

Instantly share code, notes, and snippets.

@mehmetcanyegen
Created April 28, 2020 10:34
Show Gist options
  • Save mehmetcanyegen/3bec04bde8bfbe014e48ab01e3b2791b to your computer and use it in GitHub Desktop.
Save mehmetcanyegen/3bec04bde8bfbe014e48ab01e3b2791b to your computer and use it in GitHub Desktop.
YaziyaCevir Java Version
package com.mehmetcanyegen;
public class Main {
public static final String padLeft(String str, int totalWidth){
StringBuilder sb = new StringBuilder();
sb.append("0".repeat(Math.max(0, totalWidth - str.length())));
sb.append(str);
return sb.toString();
}
public static final String yaziyaCevir(double tutar) {
String sTutar = String.format("%.2f", tutar).replace('.', ',');
String lira = sTutar.substring(0, sTutar.indexOf(','));
String kurus = sTutar.substring((sTutar.indexOf(',') + 1), (sTutar.indexOf(',') + 1)+2);
String yazi = "";
String[] birler = new String[] { "", "BİR", "İKİ", "ÜÇ", "DÖRT", "BEŞ", "ALTI", "YEDİ", "SEKİZ", "DOKUZ" };
String[] onlar = new String[] { "", "ON", "YİRMİ", "OTUZ", "KIRK", "ELLİ", "ALTMIŞ", "YETMİŞ", "SEKSEN", "DOKSAN" };
String[] binler = new String[] { "KATRİLYON", "TRİLYON", "MİLYAR", "MİLYON", "BİN", "" };
int grupSayisi = 6;
lira = padLeft(lira, (grupSayisi * 3));
String grupDegeri;
for (int i = 0; (i < (grupSayisi * 3)); i += 3) {
grupDegeri = "";
if ((!lira.startsWith("0", i))) {
grupDegeri = (grupDegeri + (birler[Integer.parseInt(lira.substring(i, i+1))] + "YÜZ"));
}
if ((grupDegeri.equals("BİRYÜZ"))) {
grupDegeri = "YÜZ";
}
grupDegeri = (grupDegeri + onlar[Integer.parseInt(lira.substring((i + 1), (i + 1)+1))]);
grupDegeri = (grupDegeri + birler[Integer.parseInt(lira.substring((i + 2), (i + 2)+1))]);
if ((!grupDegeri.equals(""))) {
grupDegeri = (grupDegeri + binler[(i / 3)]);
}
if ((grupDegeri.equals("BİRBİN"))) {
grupDegeri = "BİN";
}
yazi = (yazi + grupDegeri);
}
if ((!yazi.equals(""))) {
yazi += " TL ";
}
int yaziUzunlugu = yazi.length();
if ((!kurus.startsWith("0"))) {
yazi = (yazi + onlar[Integer.parseInt(kurus.substring(0, 1))]);
}
if ((!kurus.startsWith("0", 1))) {
yazi = (yazi + birler[Integer.parseInt(kurus.substring(1, 1+1))]);
}
if ((yazi.length() > yaziUzunlugu)) {
yazi += " KR.";
}
else {
yazi += "SIFIR KR.";
}
return yazi;
}
public static void main(String[] args) {
System.out.println(yaziyaCevir(901000.01));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment