StrToFloat com decimais igual a zero

03/01/2006

0

Boa tarde,


Alguém sabe com fazer para que na hora de converter um valor de uma string igual a 800,00 para float sejam mantidas as decimais 00.
Na hora de fazer a conversão e gravar no banco, somente são mantidas as decimais quando o valor for diferente de zero por exemplo 800,03.
Se o valor for 800,00 será gravado no banco somente 800.
Utilizei a função StrToFloat mas não funcionou. O valor informado faz parte do registro de um arquivo texto que está sendo importado para o banco.

Obrigado

Airton


Airoosp

Airoosp

Responder

Posts

03/01/2006

Edilcimar

strtofloatf(numero, ffFixed, 10,2)


Responder

03/01/2006

Airoosp

Obrigado pela informação, qual unit devo acrescentar ao projeto para poder utilizar a função strtofloatf. Utilizo Delphi 6.


Airton


Responder

03/01/2006

Edilcimar

sysutils


Responder

03/01/2006

Airoosp

Esta função não tem na Sysutils do Delphi 6, verifiquei também na unit system e também não tem.
É alguma função desenvolvida a parte?


Responder

03/01/2006

Edilcimar

não, faz parte do delphi, o meu é 7 porém uso isto desde o 4


Responder

03/01/2006

Airoosp

É possível você postar no fórum a função, pois estou procurando na Internet e não encontrei em nenhum site.


Responder

03/01/2006

Edilcimar

ela é parte integrante do delphi, isto abaixo foi tirado do próprio delphi

Converts a floating point value to a string, using a specified Format, Precision, and Digits.

Unit

SysUtils

Category

Floating point conversion routines

Delphi syntax:

function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): string; overload;
function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision, Digits: Integer; const FormatSettings: TFormatSettings
): string; overload;

C++ syntax:

extern PACKAGE AnsiString __fastcall FloatToStrF(Extended Value, TFloatFormat Format, int Precision, int Digits);
extern PACKAGE AnsiString __fastcall FloatToStrF(Extended Value, TFloatFormat Format, int Precision, int Digits, const TFormatSettings FormatSettings);

Description

FloatToStrF converts the floating-point value given by Value to its string representation.

The Value parameter is the value to convert.
The Precision parameter specifies the precision of the given value. It should be 7 or less for values of type Single, 15 or less for values of type Double, and 18 or less for values of type Extended.
The Digits and Format parameters together control how the value is formatted into a string. For details, see the description of TFloatFormat.

If the given value is a NAN (not-a-number), the resulting string is ´NAN´. If the given value is positive infinity, the resulting string is ´INF´. If the given value is negative infinity, the resulting string is ´-INF´.

The first form of FloatToStrF is not thread-safe, because it uses localization information contained in global variables. The second form of FloatToStrF, which is thread-safe, refers to localization information contained in the FormatSettings parameter. Before calling the thread-safe form of FloatToStrF, you must populate FormatSettings with localization information. To populate FormatSettings with a set of default locale values, call GetLocaleFormatSettings.


Responder

03/01/2006

Airoosp

Esta função que você passou não a mesma, você informou StrToFloatF e o descritivo que você passou é da FloatToStrF que faz a conversão de float para string. O que eu preciso é de string para float mantendo as decimais mesmo que sejam iguais a zero.


Responder

03/01/2006

Edilcimar

então desculpe foi um lapso, escrevi invertida!


Responder

03/01/2006

Airoosp

Entendi, mas você conhece alguma forma de manter as decimais para gravação no banco?

Por exemplo:


variavel string = 800,00 ao converter para float para gravação visto que o campo da tabela é number(15,2) o valor passa para 800. Preciso que grave o valor 800,00 .


Responder

03/01/2006

Edilcimar

normalmente nenhum campo flutuante grava zeros à direita, o que vc pode fazer é mostrá-los como se lá existissem


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar