Monday, December 5, 2011

Terbilang Function in Dynamics Ax in Indonesian

static TempStr numeralsToTxt_Indo(Real _num)
{
int numOfPennies = frac(_num)*100 mod 100;
int test = round(_num,0);

int numOfTenths;
str 20 ones[19], tenths[9], hundreds, thousands, millions, billions;

int temp;
str 200 returntxt;

int checkPower(int _test, int _power)
{
int numOfPower;

if (_test >= _power)
{
numOfPower = _test DIV _power;
if (numOfPower >= 100)
{
temp = numOfPower DIV 100;
returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
numOfPower = numOfPower MOD 100;
}
if (numOfPower >= 20)
{
temp = numOfPower DIV 10;
returntxt = returntxt + ' ' + tenths[temp];
numOfPower = numOfPower MOD 10;
}
if (numOfPower >= 1)
{
returntxt = returntxt + ' ' + ones[numOfPower];
numOfPower = numOfPower MOD 10;
}
switch(_power)
{
case 1000000000 :
{
returntxt = returntxt + ' ' + billions;
_test = _test MOD 1000000000;
break;
}
case 1000000 :
{
returntxt = returntxt + ' ' + millions;
_test = _test MOD 1000000;
break;
}
case 1000 :
{
returntxt = returntxt + ' ' + thousands;
_test = _test MOD 1000;
break;
}
case 100 :
{
returntxt = returntxt + ' ' + hundreds;
_test = _test MOD 100;
break;
}
}
}
return _test;
}



ones[1] = "Satu";
ones[2] = "Dua";
ones[3] = "Tiga";
ones[4] = "Empat";
ones[5] = "Lima";
ones[6] = "Enam";
ones[7] = "Tujuh";
ones[8] = "Delapan";
ones[9] = "Sembilan";
ones[10] = "Sepuluh";
ones[11] = "Sebelas";
ones[12] = "Dua Belas";
ones[13] = "Tiga Belas";
ones[14] = "Empat Belas";
ones[15] = "Lima Belas";
ones[16] = "Enam Belas";
ones[17] = "Tujuh Belas";
ones[18] = "Delapan Belas";
ones[19] = "Sembilan Belas";

tenths[1] = 'Not used';
tenths[2] = "Dua Puluh";
tenths[3] = "Tiga Puluh";
tenths[4] = "Empat Puluh";
tenths[5] = "Lima Puluh";
tenths[6] = "Enam Puluh";
tenths[7] = "Tujuh Puluh";
tenths[8] = "Delapan Puluh";
tenths[9] = "Sembilan Puluh";

hundreds = "Ratus";
thousands = "Ribu";
millions = "Juta";
billions = "Miliar";


test = checkPower(test, 1000000000);
test = checkPower(test, 1000000);
test = checkPower(test, 1000);
test = checkPower(test, 100);

if (test >= 20)
{
numOfTenths = test DIV 10;
returntxt = returntxt + ' ' + tenths[numofTenths];
numOfTenths = numOfTenths MOD 10;
test = test MOD 10;
}
if (test >= 1)
{
numOfTenths = test;
returntxt = returntxt + ' ' + ones[numOfTenths];
}

if (numOfPennies)
{
//returntxt = '***' + returntxt + ' ' + "@SYS5534" + ' ' + num2str(numOfPennies,0,0,0,0) + '/100';
//returntxt = returntxt + ' ' + num2str(numOfPennies,0,0,0,0) + '/100';
returntxt = returntxt + numeralstotxt_indo(numofpennies) + ' Sen';


}

if (strscan(strltrim(returntxt),"Satu Ribu",1,15)==1)
{
returntxt = strReplace(returntxt, "Satu Ribu", "Seribu");
}

returntxt = strReplace(returntxt, "Juta Satu Ribu", "Juta Seribu");
returntxt = strReplace(returntxt, "Satu Ratus", "Seratus");
return returntxt;
}

No comments:

Post a Comment