Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ademilson Moreira

Casas decimais com campo float

Recommended Posts

Meu banco de dados possui alguns campos tipo float.Quando coloco um componente relativo a estes campos as casas decimais aparecem vários números. Ex 1,232 aparece assim 1,232452545625755852. Como faço para limitar em tres ou quatro ou duas casas decimais ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom, qual o Bd utilizado???

 

dependendo você pode limitar por ele...

 

 

ou se quiser passar formatado para um Edit, por exemplo pode fazer da seguinte maneira:

 

var total : Double;

 

total := 12,159;

 

Edit1.text := FloatToStrf(total,ffnumber,12,2);

O resultado será 12,16... pois ele irá formatar o valor formatado como a sintaxe abaixo...

 

[Delphi]function FloatToStrF(Value: Extended; Format: TFloatFormat; Precision: Integer; Digits: Integer): string; overload;

Value - Valor

 

Format - Formato a ser apresentado... pode ser:

 

[*]ffGeneral

General number format. The value is converted to the shortest possible decimal string using scientific format. Trailing zeros are removed from the resulting string.

 

 

 

[*]ffExponent

Scientific format. The value is converted to a string of the form "-d.ddd...E+dddd". The resulting string starts with a minus sign if the number is negative, and one digit always precedes the decimal point. The total number of digits before the exponent in the resulting string (including the one before the decimal point) is given by the Precision parameter. The "E" exponent character in the resulting string is always followed by a plus or minus sign and up to four digits. The Digits parameter specifies the minimum number of digits in the exponent (between 0 and 4).

 

[*]ffFixed

Fixed point format. The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative, and at least one digit always precedes the decimal point. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18. If the number of digits to the left of the decimal point is greater than the specified precision, the resulting value will use scientific format. The resulting values is padded with zeros when the Digits parameter is higher than the number of digits dictated by precision. For example, given ffFixed with Precision set to 5 and digits set to 3, fomatting 345.6789 gives the string '345.680', padding with zeros after the precision is met.

 

[*]ffNumber

Number format. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format, except that the resulting string contains thousandth separators. The resulting values is padded with zeros when the Digits parameter is higher than the number of digits dictated by precision. For example, given ffNumber with Precision set to 5 and digits set to 3, fomatting 345.6789 gives the string '345.680', padding with zeros after the precision is met.

 

[*]ffCurrency

Currency format. The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString , CurrencyFormat , NegCurrFormat , ThousandSeparator , and DecimalSeparator global variables, all of which are initialized from the Currency Format in the International section of the Windows Control Panel. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18. The resulting values is padded with zeros when the Digits parameter is higher than the number of digits dictated by precision. For example, given ffCurrency with Precision set to 5 and digits set to 3, fomatting 345.6789 gives the string '345.680', padding with zeros after the precision is met.

 

 

Precision - Deve ser 7 ou menos para valores do tipo Single, 15 ou menos para valores do tipo Double e 18 ou menos para valores do tipo Extended.

 

 

Digits - Número de casas decimais.

 

 

 

Flw aew!!!

 

Espero ter ajudado... http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

faz assim... no campo da sua Query, table, ou dataset... enfim.. na propriedade displayFormat, você coloca uma mascara assim #.## ele vai trazer um número 1,232452545625755852 assim: 1,23não tendo o segundo digito vai trazer soh o primeiro, ex: 0,2você colocando a mascara #.00 ele vai mostrar o numero com duas casas decimais... independente de soh ter uma ou nenhuma... ex: 12,00 2,10 dica: clica na propriedade displayFormat no object inspector e aperta f1... lá explica, em ingles, mas explica

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.