Texto por extenso.
Olá pessoal,
alguém saberia me dizer como exibir um valor monetário por extenso?
Por exemplo, o texto de um TEdit = ´R$ 750,00´.
Obrigado.
PS: Este é o melhor FORUM DELPHI do Brasil.
alguém saberia me dizer como exibir um valor monetário por extenso?
Por exemplo, o texto de um TEdit = ´R$ 750,00´.
Obrigado.
PS: Este é o melhor FORUM DELPHI do Brasil.
Weliton Oliveira
Curtidas 0
Respostas
Nilsonoliveiratec
28/05/2005
Usa essa função:
function Extenso(Valor:Extended): string;
const
aCifra : array [1..6,1..2] of string =
((´trilhão, e ´,´trilhões, e ´),(´bilhão, e ´,´bilhões, e ´),
(´milhão, e ´,´milhões, e ´),(´mil, e ´,´mil, e ´),
(´real, e ´,´reais, e ´),(´centavo, ´,´centavos, ´));
var
text,s: string;
num,i : longint;
begin
text := ´´;
s := PadL(FloatToStrF(Valor,ffFixed,18,2),18,´0´);
for i := 1 to 6 do
begin
if i <> 6
then num := StrToInt(Copy(s,1,3))
else num := StrToInt(Copy(s,2,2));
s := Copy(s,4,length(s)-3);
if num <> 0
then text := text + ExtCem(num)+iif(num = 1,aCifra[i,1],aCifra[i,2]);
if (num = 0) and (i = 5) and (length(text)>0)
then text := Copy(text,1,length(text)-4)+´ reais, e ´;
end;
result := Copy(text,1,length(text)-4);
end;
Espero q te ajude ok!
function Extenso(Valor:Extended): string;
const
aCifra : array [1..6,1..2] of string =
((´trilhão, e ´,´trilhões, e ´),(´bilhão, e ´,´bilhões, e ´),
(´milhão, e ´,´milhões, e ´),(´mil, e ´,´mil, e ´),
(´real, e ´,´reais, e ´),(´centavo, ´,´centavos, ´));
var
text,s: string;
num,i : longint;
begin
text := ´´;
s := PadL(FloatToStrF(Valor,ffFixed,18,2),18,´0´);
for i := 1 to 6 do
begin
if i <> 6
then num := StrToInt(Copy(s,1,3))
else num := StrToInt(Copy(s,2,2));
s := Copy(s,4,length(s)-3);
if num <> 0
then text := text + ExtCem(num)+iif(num = 1,aCifra[i,1],aCifra[i,2]);
if (num = 0) and (i = 5) and (length(text)>0)
then text := Copy(text,1,length(text)-4)+´ reais, e ´;
end;
result := Copy(text,1,length(text)-4);
end;
Espero q te ajude ok!
GOSTEI 0