Colocar virgula em uma string... URGENTE....

Delphi

12/02/2004

Olá galera,
Pessoal, estou extraindo valores de um txt e possuo as seguintes strings que pro meu BD entra como float.
EX.:

TXT
0000000000163211 (é assim que extraio o ´valor´)

quando jogo isso para o BD ele formata da seguinte forma:
16.3211,00

Sendo que na verdade o valor correto é:
1.632,00

Como posso resolver esse problema ?

Segue um trecho do codigo:

TPE.FieldByName(´DN_VLR_PE´).AsFloat := StrToFloat(Copy(Linha,195,16));

OBS: Linha, é a variavel que recebe o conteudo do txt.

Um abraço a todos
Diego[b:0501e163fa][/b:0501e163fa]


Diegodelphi

Diegodelphi

Curtidas 0

Respostas

Pr.mas

Pr.mas

12/02/2004

Segue uma função que vai resolver

function StringToFloat(s : string) : string;
{Formata valores de R$ 1.200,00´ para 1200,00 }
var
i :Integer;
t : string;
SeenDecimal,SeenSgn : Boolean;
begin
t := ´´;
SeenDecimal := False;
SeenSgn := False;
{Percorre os caracteres da string:}
for i := Length(s) downto 0 do
{Filtra a string, aceitando somente números e separador decimal:}
if (s[i] in [´0´..´9´, ´-´,´+´,DecimalSeparator]) then
begin
if (s[i] = DecimalSeparator) and (not SeenDecimal) then
begin
t := s[i] + t;
SeenDecimal := True;
end
else if (s[i] in [´+´,´-´]) and (not SeenSgn) and (i = 1) then
begin
t := s[i] + t;
SeenSgn := True;
end
else if s[i] in [´0´..´9´] then
begin
t := s[i] + t;
end;
end;
end;

Marcos


GOSTEI 0
POSTAR