XGhost
Član broj: 33279 Poruke: 331 *.PPPoE-1109.sa.bih.net.ba.
|
NASAO SAM KOD
Function CurencyToStr (S : String) : String;
Const
Separator = ',';
StotiFormat = ' i %s/100';
Jedinice : Array [0..1, 0..19] Of String =
(('', 'jedna', 'dve', 'tri', 'cetiri',
'pet', 'sest', 'sedam', 'osam', 'devet',
'deset', 'jedanaest', 'dvanaest', 'trinaest', 'cetrnajest',
'petnaest', 'sesnaest', 'sedamnaest', 'osamnaest', 'devetnaest'),
('', 'jedan', 'dva', 'tri', 'cetiri',
'pet', 'sest', 'sedam', 'osam', 'devet',
'deset', 'jedanaest', 'dvanaest', 'trinaest', 'cetrnajest',
'petnaest', 'sesnaest', 'sedamnaest', 'osamnaest', 'devetnaest')
);
Desetice : Array [2..9] Of String =
('dvadeset', 'trideset', 'cetrdeset', 'pedeset',
'sezdeset', 'sedamdeset', 'osamdeset', 'devedeset');
Stotine : Array [0..9] Of String =
('', 'sto', 'dvesta', 'trista', 'cetirsto',
'petsto', 'sesto', 'sedamsto', 'osamsto', 'devetsto');
Prilozi : Array [1..4, -1..5] Of String =
((' dinar', 'a', '', 'a', 'a', 'a', 'a'),
('hiljad', 'a', 'a', 'e', 'e', 'e', 'a'),
('milion', 'a', '', 'a', 'a', 'a', 'a'),
('milijard', 'i', 'a', 'e', 'e', 'e', 'i')
);
Var
Stoti : String;
Trojka,
Temp : String;
X : Integer;
Begin
Stoti :='';
If Pos (Separator, S) > 0 Then
Begin
Stoti := Copy (S, Pos (Separator, S) + 1, Length (S));
S := Copy (S, 1, Pos (Separator, S) - 1);
// Ovde bi eventualno trebalo umesto secenja na dve decimale
// uraditi zaokruzivanje
If Length (Stoti) > 2 Then Stoti := Copy (Stoti, 1, 2);
End;
While Length (Stoti) < 2 Do Stoti := '0' + Stoti;
// Ne moze StrToInt jer je maxint 2147483647
If StrToFloat (S) = 0 Then
Result := 'nula dinara'
Else
Begin
While Length (S) Mod 3 <> 0 Do S := '0' + S;
Result := '';
For X := 1 To 4 Do
Begin
Trojka := Copy (S, Length (S) - 2, 3);
Delete (S, Length (S) - 2, 3);
If Trojka = '' Then
Trojka := '000';
If Trojka <> '000' Then
Begin
If Trojka [2] In ['0', '1'] Then
Temp := Jedinice [X mod 2, StrToInt (Trojka [2] + Trojka [3])]
Else
Temp := Desetice [StrToInt (Trojka [2])] + Jedinice [X mod 2, StrToInt (Trojka [3])];
Temp := Stotine [StrToInt (Trojka [1])] + Temp;
If StrToInt (Trojka [2] + Trojka[3]) <= 5 Then
Temp := Temp + Prilozi [x, -1] + Prilozi [x, StrToInt (Trojka[2] + Trojka[3])]
Else
Temp := Temp + Prilozi [x, -1] + Prilozi [x, 5];
Result := Temp + Result;
End
Else
If X = 1 Then
Result := Result + ' dinara';
End;
End;
Result := Result + Format (StotiFormat, [Stoti]);
end;
**********************************************************
Moze li jos samo malo objasnjenja kako da ovo povezem na koponente npr
Broj koji tebam prevesti nalazi se u Edit1 a rezutat u tekstu trebam dobiti u
Edit2.
**********************************************************
|