PHP deja neturiu, aplamai mano nuomuone toks dalykas turetu ieiti i pvz. kad ir windows api prie regional settings ir vadintis kazkas tokio ToWords, na ir del PHP kazkas panasaus turetu buti bet deja nera:)
Kazkada paciam reikejo ant C# sito gabalo, tai radau tik Visual Basic daryta, ji siunciu prie laisko, pats poto su kazkokiu Visual Basic to C# toolsu konvertavau i C#, na C# sintakse panasesne i PHP nei VB, tai duodu ir savaji varianta, tiesa ta funkcija reiketu rimciau perrasyti, man tiesiog nebuvo laiko, na bet gal pravers (visumoje sis variantas yra grubus vertimas is VB i C#):
public static string SumaZodziais (decimal suma, bool itIsMoney)
{
Int64 sveikaDalis = (Int64)suma;
string retVal = sveikaDalis.ToString ();
int I;
int J;
int K;
int sumaLength = retVal.Length;
int[] Narys = new int[8];
bool Nedesimt;
string[] Vienas = { "vienas ", "du ", "trys ", "keturi ", "penki ", "ei ", "septyni ", "atuoni ", "devyni " };
string[] Lika = { "vienuolika ", "dvylika ", "trylika ", "keturiolika ", "penkiolika ", "eiolika ", "septyniolika ", "atuoniolika ", "devyniolika " };
string[] Desimt = { "deimt ", "dvideimt ", "trisdeimt ", "keturiasdeimt ", "penkiasdeimt ", "eiasdeimt ", "septyniasdeimt ", "atuoniasdeimt ", "devyniasdeimt " };
string[] Simtas = { "imtas ", "imtai " };
string[] Tukst = { "tkstantis ", "tkstaniai ", "tkstani " };
string[] Milion = { "milijonas ", "milijonai ", "milijonu " };
if (sumaLength < 10)
{
for (I = sumaLength - 1; I >= 0; I--)
{
Narys[sumaLength - (I + 1)] = Convert.ToInt32 (
retVal.Substring (I, 1));
}
if (suma < 0)
retVal = "minus ";
else
retVal = "";
K = 0;
for (J = (sumaLength - 1) / 3; J >= 0; J--)
{
Nedesimt = false;
for (I = sumaLength - 1 - K; I >= J * 3; I--)
{
switch (I - J * 3)
{
case 2:
if (Narys[I] != 0)
{
retVal = retVal + Vienas[Narys[I] - 1];
if (Narys[I] == 1)
retVal = retVal + Simtas[0];
else
retVal = retVal + Simtas[1];
}
break;
case 1:
if (Narys[I] == 1 & Narys[I - 1] != 0)
{
Nedesimt = true;
}
else
{
if (Narys[I] != 0)
retVal = retVal + Desimt[Narys[I] - 1];
}
break;
case 0:
if (Nedesimt)
{
retVal = retVal + Lika[Narys[I] - 1];
}
else
{
if (Narys[I] != 0)
retVal = retVal + Vienas[Narys[I] - 1];
}
break;
}
}
K = sumaLength - J * 3;
switch (J)
{
case 0:
if (retVal == "" | retVal == "minus ")
{
retVal = retVal + "nulis ";
}
if (itIsMoney)
{
int centai = (int)(Math.Round (suma- sveikaDalis, 2) * 100);
retVal += "Lt. " + string.Format("{0:00}", centai) + " ct."; // VBA: Str = Str & "Lt " & Format((Abs(Suma) - Int(Abs(Suma))) * 100, "00") & " ct"
}
break;
case 1:
if (K == 1 | (Narys[J * 3] != 0 & Narys[1 + J * 3] != 1))
{
if (Narys[J * 3] == 1)
retVal += Tukst[0];
else
retVal += Tukst[1];
}
else
{
if (Narys[3] + Narys[4] + Narys[5] != 0)
retVal += Tukst[2];
}
break;
case 2:
if (K == 1 | (Narys[J * 3] != 0 & Narys[1 + J * 3] != 1))
{
if (Narys[J * 3] == 1)
retVal = retVal + Milion[0];
else
retVal = retVal + Milion[1];
}
else
{
retVal = retVal + Milion[2];
}
break;
}
}
return retVal;
//Zodis = Chr (Asc (retVal) - 32) + Right (retVal , Len (retVal) - 1);
}
else
{
return "Tiek negali buti";
}
}
public enum DigitType
{
Quantity,
Money
}
// private because unfinished to not use this
static string ToWords (
double suma,
DigitType type)
{
int I, J, K;
string retVal = string.Empty;
bool Nedesimt;
string sveikaDalis = ((Int64)suma).ToString ();
// predefine data arrays
string[] Vienas = { "vienas ", "du ", "trys ", "keturi ", "penki ", "ei ", "septyni ", "atuoni ", "devyni " };
string[] Lika = { "vienuolika ", "dvylika ", "trylika ", "keturiolika ", "penkiolika ", "eiolika ", "septyniolika ", "atuoniolika ", "devyniolika " };
string[] Desimt = { "deimt ", "dvideimt ", "trisdeimt ", "keturiasdeimt ", "penkiasdeimt ", "eiasdeimt ", "septyniasdeimt ", "atuoniasdeimt ", "devyniasdeimt " };
string[] Simtas = { "imtas ", "imtai " };
string[] Tukst = { "tkstantis ", "tkstaniai ", "tkstani " };
string[] Milion = { "milijonas ", "milijonai ", "milijon " };
if (suma.ToString ().Length < 10)
{
if (suma < 0)
retVal = "minus ";
else
retVal = "";
K = 0;
for (J = (sveikaDalis.Length - 1) / 3; J >= 0; J--)
{
Nedesimt = false;
for (I = sveikaDalis.Length - 1 - K; I >= J * 3; I--)
{
switch (I - J * 3)
{
case 2:
if (sveikaDalis[I] != 0)
{
retVal = retVal + Vienas[sveikaDalis[I] - 1];
if (sveikaDalis[I] == 1)
retVal = retVal + Simtas[0];
else
retVal = retVal + Simtas[1];
}
break;
case 1:
if (sveikaDalis[I] == 1 & sveikaDalis[I - 1] != 0)
{
Nedesimt = true;
}
else
{
if (sveikaDalis[I] != 0)
retVal = retVal + Desimt[sveikaDalis[I] - 1];
}
break;
case 0:
if (Nedesimt)
{
retVal = retVal + Lika[sveikaDalis[I] - 1];
}
else
{
if (sveikaDalis[I] != 0)
retVal = retVal + Vienas[sveikaDalis[I] - 1];
}
break;
}
}
K = sveikaDalis.Length - J * 3;
switch (J)
{
case 0:
if (retVal == "" | retVal == "minus ")
retVal = retVal + "nulis ";
if (type == DigitType.Money)
{
#warning todo: implement suma zodziais jei reiks centu ar pinigu
//retVal += "Lt " + Format ((Abs (suma) - Int (Abs (suma))) * 100, "00") + " ct";
}
break;
case 1:
if (K == 1 | (sveikaDalis[J * 3] != 0 & sveikaDalis[1 + J * 3] != 1))
{
if (sveikaDalis[J * 3] == 1)
retVal += Tukst[0];
else
retVal += Tukst[1];
}
else
{
if (sveikaDalis[3] + sveikaDalis[4] + sveikaDalis[5] != 0)
retVal += Tukst[2];
}
break;
case 2:
if (K == 1 | (sveikaDalis[J * 3] != 0 & sveikaDalis[1 + J * 3] != 1))
{
if (sveikaDalis[J * 3] == 1)
retVal = retVal + Milion[0];
else
retVal = retVal + Milion[1];
}
else
{
retVal = retVal + Milion[2];
}
break;
}
}
return retVal;
}
else
{
return "Skaiius per didelis";
}
return retVal;
}
}
Freelancer Developer
www.lythum.lt
