Amount in words (in Latvian) – pascal

pascal Add comments

function Replace(strSource:string; strToFind:string; strReplace:string): string;
    var sresult:string; i:integer;
    begin
   i:=1;
    while i<=length(strSource) do
    begin
    if copy(strSource,i,length(strToFind)) = strToFind then
    begin
    sresult := sresult + strReplace;
    i:=i+length(strToFind);
    end
    else
    begin
    sresult := sresult + copy(strSource,i,1);
    i:=i+1;
    end;
    end;
    result := sresult
end;  

function Get_10(iOne:integer):string;|>
begin
Result:='';
If (iOne>0) And (iOne<20) Then
Case iOne of
1:Result:='viens ';
2:Result:='divi ';
3:Result:='trīs ';
4:Result:='četri ';
5:Result:='pieci ';
6:Result:='seši ';
7:Result:='septiņi ';
8:Result:='astoņi ';
9:Result:='deviņi ';
10:Result:='desmit ';
11:Result:='vienpadsmit ';
12:Result:='divpadsmit ';
13:Result:='trīspadsmit ';
14:Result:='četrpadsmit ';
15:Result:='piecpadsmit ';
16:Result:='sešpadsmit ';
17:Result:='septiņpadsmit ';
18:Result:='astoņpadsmit ';
19:Result:='deviņpadsmit ';
end;
if (iOne>=20) and (iOne<100) Then
begin
case Trunc(Int(iOne/10)) of
2:Result:='divdesmit ';
3:Result:='trīsdesmit ';
4:Result:='četrdesmit ';
5:Result:='piecdesmit ';
6:Result:='sešdesmit ';
7:Result:='septiņdesmit ';
8:Result:='astoņdesmit ';
9:Result:='deviņdesmit ';
end;
Case Trunc(Int(iOne - Int(iOne / 10) * 10)) of
1:Result:=Result+'viens ';
2:Result:=Result+'divi ';
3:Result:=Result+'trīs ';
4:Result:=Result+'četri ';
5:Result:=Result+'pieci ';
6:Result:=Result+'seši ';
7:Result:=Result+'septiņi ';
8:Result:=Result+'astoņi ';
9:Result:=Result+'deviņi ';
end;
end;
if Result='' then Result:='0 ';
End;

Function GetCurrency(iOne:integer; txt1,txt2:string):string;
begin
Result:='';
Result:=Get_10(iOne);
if Copy(Result,length(Result)-5,6)='viens ' then
Result:=Result+txt1 else
Result:=Result+txt2;
End;

function NumberToWords(KOPA:Currency;Ucase:boolean):String;
var
l:integer;
value:integer;
stringvalue,sant,santimms:string;
number:extended;
santims:integer;
begin

number:=Trunc(KOPA);
santimms:=Replace(Format('%.2n', [Frac(KOPA)]),'0.','');

  if santimms='1.00' then
  begin
    number:=number+1;
    santimms:=Replace(santimms,'1.','');
  end;

santims:=StrToInt(santimms);

value:=Trunc(Int(number));
stringvalue:=IntToStr(value);

l:=Length(stringvalue);
case value of
0..99:Result:=Get_10(value);
100..999:Result:=GetCurrency(value div 100,'simts ','simti ')+Get_10(StrToInt(Copy(stringvalue,l-1,2)));
1000..9999:
begin
Result:=GetCurrency(value div 1000,'tūkstotis ','tūkstoši ');
if Copy(stringvalue,l-2,1)<>'0' then
Result:=Result+GetCurrency(StrToInt(Copy(stringvalue,l-2,1)),'simts ',
'simti ');
Result:=Result+Get_10(StrToInt(Copy(stringvalue,l-1,2)));
end;
10000..99999:
begin
Result:=GetCurrency(value div 1000,'tūkstotis ','tūkstoši ');
if copy(stringvalue,l-2,1)<>'0' then
Result:=Result+GetCurrency(StrToInt(Copy(stringvalue,l-2,1)),'simts ',
'simti ');
Result:=Result+Get_10(StrToInt(Copy(stringvalue,l-1,2)));
end;
100000..999999:
begin
Result:=GetCurrency(value div 100000,'simts ','simti ')+
GetCurrency(StrToInt(Copy(stringvalue,l-4,2)),'tūkstotis ','tūkstoši ');
if copy(stringvalue,l-2,1)<>'0' then
Result:=Result+GetCurrency(StrToInt(Copy(stringvalue,l-2,1)),'simts ',
'simti ');
Result:=Result+Get_10(StrToInt(Copy(stringvalue,l-1,2)));
end;
1000000..9999999:
begin
Result:=GetCurrency(value div 1000000,'miljons ','miljoni ') ;
if Copy(stringvalue,l-5,1)<>'0' then
Result:=Result+GetCurrency(StrToInt(Copy(stringvalue,l-5,6)) div
100000,'simts ','simti')+GetCurrency(StrToInt(Copy(stringvalue,l-4,2)),'tūkstotis ','tūkstoši ');
if copy(stringvalue,l-2,1)<>'0' then
Result:=Result+GetCurrency(StrToInt(Copy(stringvalue,l-2,1)),'simts ',
'simti ');
Result:=Result+Get_10(StrToInt(Copy(stringvalue,l-1,2)));
end;
end;
if Copy(Result,length(Result)-5,6)='viens ' then
Result:=Result+'lats ' else
Result:=Result+'lati ';

sant:=Get_10(santims);
if Copy(sant,Length(sant)-5,6)='viens ' then
Result:=Result+sant+'santīms' else
Result:=Result+sant+'santīmi';
if Ucase then Result:=AnsiUppercase(Result) else
Result:=AnsiUpperCase(Copy(Result,1,1))+Copy(Result,2,Length(Result));
end;

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in