Functie: numeric in suma text

Lasă un comentariu

19 Decembrie 2013 de liviustoica55


public static TempStr numeralsToTxt_RO(real _suma)

{

real suma;

str hundreds[10]; //sute

str tenths[10]; //zeci

str ones[10]; //unitati

 

str singularSuffix[5];

str pluralSuffix[5];

str overTen[10]; //10–>19

 

str digitSum; //suma cifre

 

int intAmount;

 

str 1000 integerPart; //Parte intreaga

str 1000 decimalPart; //Partea zecimala

int amountLenght;

int noOf3Groups;

int zecimalPartInt;

 

int i;

int contorString;

 

int number1;

int number2;

int number3;

 

str 1000 localString;

 

#Define.text_null(”)

#Define.text_100(‘o suta’)

#Define.text_200(‘doua sute’)

#Define.text_300(‘trei sute’)

#Define.text_400(‘patru sute’)

#Define.text_500(‘cinci sute’)

#Define.text_600(‘sase sute’)

#Define.text_700(‘sapte sute’)

#Define.text_700(‘sapte sute’)

#Define.text_800(‘opt sute’)

#Define.text_900(‘noua sute’)

 

#Define.text_20(‘douazeci’)

#Define.text_30(‘treizeci’)

#Define.text_40(‘patruzeci’)

#Define.text_50(‘cincizeci’)

#Define.text_60(‘saizeci’)

#Define.text_70(‘saptezeci’)

#Define.text_80(‘optzeci’)

#Define.text_90(‘nouazeci’)

 

 

#Define.text_3(‘trei’)

#Define.text_4(‘patru’)

#Define.text_5(‘cinci’)

#Define.text_6(‘sase’)

#Define.text_7(‘sapte’)

#Define.text_8(‘opt’)

#Define.text_9(‘noua’)

 

 

#Define.singularSuffix_leu(‘leu’)

#Define.singularSuffix_mie(‘mie’)

#Define.singularSuffix_milion(‘milion’)

#Define.singularSuffix_miliard(‘miliard’)

#Define.singularSuffix_miedemiliarde(‘mie de miliarde’)

 

#Define.pluralSuffix_lei(‘lei’)

#Define.pluralSuffix_mii(‘mii’)

#Define.pluralSuffix_milioane(‘milioane’)

#Define.pluralSuffix_miliarde(‘miliarde’)

#Define.pluralSuffix_miidemiliarde(‘mii de miliarde’)

 

 

#Define.text_10(‘zece’)

#Define.text_11(‘unsprezece’)

#Define.text_13(‘treisprezece’)

#Define.text_14(‘paisprezece’)

#Define.text_15(‘cincisprezece’)

#Define.text_16(‘saisprezece’)

#Define.text_17(‘saptesprezece’)

#Define.text_18(‘optsprezece’)

#Define.text_19(‘nouasprezece’)

 

#Define.text_un(‘un’)

#Define.text_unu(‘unu’)

#Define.text_una(‘una’)

 

#Define.text_doi(‘doi’)

#Define.text_doua(‘doua’)

 

#Define.text_doisprezece(‘doisprezece’)

#Define.text_douasprezece(‘douasprezece’)

 

#Define.text_zerolei(‘zero lei’)

#Define.text_si(‘si’)

#Define.text_de(‘de’)

#Define.text_ban(‘ban’)

#Define.text_bani(‘bani’)

 

#Define.text_0(‘0’)

#Define.text_1(‘1’)

 

 

 

 

////////////////////////////////////////////////////////////////////

//**************************initialization**************************

////////////////////////////////////////////////////////////////////

void Init()

{ //Initialization of the array

 

//for hundred

hundreds[1] = #text_null;

hundreds[2] = #text_100;

hundreds[3] = #text_200;

hundreds[4] = #text_300;

hundreds[5] = #text_400;

hundreds[6] = #text_500;

hundreds[7] = #text_600;

hundreds[8] = #text_700;

hundreds[9] = #text_800;

hundreds[10] = #text_900;

 

//for tenths

tenths[1] = #text_null;

tenths[2] = #text_null;

tenths[3] = #text_20;

tenths[4] = #text_30;

tenths[5] = #text_40;

tenths[6] = #text_50;

tenths[7] = #text_60;

tenths[8] = #text_70;

tenths[9] = #text_80;

tenths[10] = #text_90;

 

//for units

ones[1] = #text_null;

ones[2] = #text_null;

ones[3] = #text_null;

ones[4] = #text_3;

ones[5] = #text_4;

ones[6] = #text_5;

ones[7] = #text_6;

ones[8] = #text_7;

ones[9] = #text_8;

ones[10] = #text_9;

 

// suffix singular

singularSuffix[1] = #singularSuffix_leu;

singularSuffix[2] = #singularSuffix_mie;

singularSuffix[3] = #singularSuffix_milion;

singularSuffix[4] = #singularSuffix_miliard;

singularSuffix[5] = #singularSuffix_miedemiliarde;

 

// suffix plural

pluralSuffix[1] = #pluralSuffix_lei;

pluralSuffix[2] = #pluralSuffix_mii;

pluralSuffix[3] = #pluralSuffix_milioane;

pluralSuffix[4] = #pluralSuffix_miliarde;

pluralSuffix[5] = #pluralSuffix_miidemiliarde;

 

//10–>19

overTen[1] = #text_10;

overTen[2] = #text_11;

overTen[3] = #text_null;

overTen[4] = #text_13;

overTen[5] = #text_14;

overTen[6] = #text_15;

overTen[7] = #text_16;

overTen[8] = #text_17;

overTen[9] = #text_18;

overTen[10] = #text_19;

}

////////////////////////////////////////////////////////////////////

 

////////////////////////////////////////////////////////////////////

//**************************build string from value*****************

////////////////////////////////////////////////////////////////////

void buildString(str _string, str _value)

{

if (_value != ”)

{

if (_string == ”)

digitSum = _value;

else

digitSum = _string + ‘ ‘ + _value;

}

}

////////////////////////////////////////////////////////////////////

 

////////////////////////////////////////////////////////////////////

//*************************ending for 1,2,12******************

////////////////////////////////////////////////////////////////////

str ending(int pos1, int pos2,int pos3,int contor, int strlenght)

{

str ret;

;

 

if(pos3 == 1 && pos2 != 1)

{

if(contor ==1 || contor ==3 || contor==4)

{

if(pos2 == 0 && pos1 == 0 && (contor ==3 || contor == 4) || strlenght == 1)

ret = #text_un;

else

ret = #text_unu;

}

else

ret = #text_una;

}

else

{

if(pos3 == 2)

{

if(pos2 != 1)

{

if (contor == 1)

ret = #text_doi;

else

ret = #text_doua;

}

else

{

if(contor == 1)

ret = #text_doisprezece;

else

ret = #text_douasprezece;

}

}

}

 

return ret;

}

////////////////////////////////////////////////////////////////////

 

////////////////////////////////////////////////////////////////////

//*************************sufix for 1******************

////////////////////////////////////////////////////////////////////

str suffix(int pos1, int pos2, int pos3, int contor, str oneString)

{

str ret;

;

 

if(contor == 1)

{

if(oneString == #text_1)

ret = #singularSuffix_leu;

else

ret = #pluralSuffix_lei;

}

else

{

if(pos1 == 0 && pos2 == 0 && pos3 == 1)

ret = singularSuffix[Contor];

else

{

if (!(pos1 == 0 && pos2 == 0 && pos3 == 0))

ret = pluralSuffix[contor];

}

}

return ret;

}

////////////////////////////////////////////////////////////////////

 

;

Init();

suma = abs(_suma);

 

//BP Deviation Documented

intAmount = real2int(suma);

 

integerPart = int2str(intAmount);

zecimalPartInt = (suma – intAmount) * 100;

decimalPart = int2str(zecimalPartInt);

 

//integer part – transformation

amountLenght = strlen(integerPart);

noOf3Groups = real2int(roundup(amountLenght/3,1));

 

if (amountLenght == 1 && integerPart == #text_0)

{

digitSum = #text_zerolei;

}

else

{

contorString = 1;

for(i = noOf3Groups; i>=1;i–)

{

if(i == noOf3Groups)

localString = substr(integerPart,contorString,(3-(noOf3Groups * 3 – amountLenght)));

else

localString = substr(integerPart,contorString,3);

 

switch (strlen(localString))

{

case 1:

number1 = 0;

number2 = 0;

number3 = str2int(localString);

break;

 

case 2:

number1 = 0;

number2 = str2int(substr(localString,1,1));

number3 = str2int(substr(localString,2,1));

break;

 

case 3:

number1 = str2int(substr(localString,1,1));

number2 = str2int(substr(localString,2,1));

number3 = str2int(substr(localString,3,1));

break;

}

 

buildString(digitSum,hundreds[number1 + 1]);

buildString(digitSum,tenths[number2 + 1]);

 

if(number2 >= 2 && number3 > 0)

buildString(digitSum,#text_si);

 

if(number2 == 1)

buildString(digitSum,overTen[number3 + 1]);

else

buildString(digitSum,ones[number3 + 1]);

 

buildString(digitSum,ending(number1,number2,number3,i,amountLenght));

 

if(number2 >= 2)

buildString(digitSum,#text_de);

 

buildString(digitSum,suffix(number1,number2,number3,i,localString));

 

if(i == noOf3Groups)

contorString = contorString + (3-(noOf3Groups*3 – amountLenght));

else

contorString = contorString + 3;

}

}

 

 

//decimal part – transformation

if(decimalPart == #text_0)

return digitSum;

 

buildString(digitSum,#text_si);

 

switch (strlen(decimalPart))

{

case 1:

number1 = 0;

number2 = 0;

number3 = str2int(decimalPart);

break;

 

case 2:

number1 = 0;

number2 = str2int(substr(decimalPart,1,1));

number3 = str2int(substr(decimalPart,2,1));

break;

}

 

buildString(digitSum,tenths[number2 + 1]);

 

if(number2 >= 2 && number3 > 0)

buildString(digitSum,#text_si);

 

if(number2 == 1)

buildString(digitSum,overTen[number3 + 1]);

else

buildString(digitSum,ones[number3 + 1]);

 

buildString(digitSum,ending(number1,number2,number3,1,STRLEN(decimalPart)));

 

if(number2 >= 2)

buildString(digitSum,#text_de);

 

if(decimalPart == #text_1)

buildString(digitSum,#text_ban);

else

buildString(digitSum,#text_bani);

 

 

return digitSum;

 

}

Lasă un răspuns

Completează mai jos detaliile despre tine sau dă clic pe un icon pentru autentificare:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

%d blogeri au apreciat asta: