[ XGhost @ 13.05.2006. 21:21 ] @
Kako da prikazem slovima npr racun iznosi 245 21,50
kako da to prikazem da pise
dvjestoceterdesetpethiljadadvadesetjedan /50
[ reiser @ 13.05.2006. 22:28 ] @
http://www.elitesecurity.org/tema/117986-Pretvaranje-broja-tekst
[ XGhost @ 13.05.2006. 23:27 ] @
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.
**********************************************************





[ IvanBeograd @ 13.05.2006. 23:50 ] @
Primer uz pomoc f-je koja je postovana!Pozzz
[ Nemanja Avramović @ 14.05.2006. 02:09 ] @
http://www.elitesecurity.org/tema/99655/
[ escape:: @ 14.05.2006. 22:01 ] @
Prilagodi kod kojeg možeš naći na mom site-u:

www.coderefectory.com
[ Bojan Kopanja @ 17.05.2006. 09:48 ] @
@XGhost

Nisam sad detaljno gledao ovaj kod koji si pronasao, ali dobro pogledaj tu temu do kraja posto smo usput otklanjali neke sitne bagove u funkciji tako da je tek na kraju ta funkcija bila 99,999% super ( pre ovoga je bila samo 99% super ). Cisto da nemas neke sitne propuste u prebacivanju...
[ contrib3007 @ 20.03.2014. 15:18 ] @
Napisao sam Ruby biblioteku koja to radi:

https://github.com/pythogorian/trange_frange

Pozdrav