Board index » delphi » FloatToStr, 2 decimals

FloatToStr, 2 decimals

Hello!

I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
I use a FloatToStr function, but it doesn't seem to work. Can anybody help
me?

Regards  Gun-May

 

Re:FloatToStr, 2 decimals


Quote
Gun-May ?hman wrote:
> I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
> I use a FloatToStr function, but it doesn't seem to work. Can anybody help
> me?

Try Format, the following should show MyFloat with two decimals.

 MyLabel.Caption := Format('%n',[MyFloat]);

Re:FloatToStr, 2 decimals


In article <767n97$hq...@news1.global-one.fi>, "Gun-May ?hman"

Quote
<gun-may.oh...@merval.fi> writes:
>I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
>I use a FloatToStr function, but it doesn't seem to work. Can anybody help
>me?

Use Format.

MyLabel.Caption := Format('%.2f', [MyFloat]);

If you want comma thousand markers use Format('%.2n', [MyFloat]);.

Alan Lloyd
alangll...@aol.com

Re:FloatToStr, 2 decimals


Just try using FormatFloat('0.00',MyNum);
Quote
Gun-May ?hman wrote in message <767n97$hq...@news1.global-one.fi>...
>Hello!

>I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
>I use a FloatToStr function, but it doesn't seem to work. Can anybody help
>me?

>Regards  Gun-May

Re:FloatToStr, 2 decimals


On Mon, 28 Dec 1998 12:56:22 +0200, "Gun-May ?hman"

Quote
<gun-may.oh...@merval.fi> wrote:
>Hello!

>I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
>I use a FloatToStr function, but it doesn't seem to work. Can anybody help
>me?

>Regards  Gun-May

Hi there

have you tried using the FloatToStrF   function ?  this will allow you
to format the result the way you want.
for example....

MyLabel.Caption := FloatToStrF(mynumber,fffixed,6,2);

look up FloatToStrF in delpi help for all the options.

hope this is of some use

Re:FloatToStr, 2 decimals


In article <36909e5f.2188...@news.ion.com.au>,

Quote
  k...@ion.com.au wrote:
> On Mon, 28 Dec 1998 12:56:22 +0200, "Gun-May ?hman"
> <gun-may.oh...@merval.fi> wrote:

> >Hello!

> >I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
> >I use a FloatToStr function, but it doesn't seem to work. Can anybody help
> >me?

> >Regards  Gun-May

How about

Label1.Caption := Format('%5.2n', [MyFloat]);//n will give you commas
//Lookup Format under the help

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:FloatToStr, 2 decimals


Quote
On Mon, 04 Jan 1999 11:06:40 GMT, k...@ion.com.au wrote:
>On Mon, 28 Dec 1998 12:56:22 +0200, "Gun-May ?hman"
><gun-may.oh...@merval.fi> wrote:

>>Hello!

>>I have a little problem. I want to write, in a label, 2 decimals e.g 2.54
>>I use a FloatToStr function, but it doesn't seem to work. Can anybody help
>>me?

>>Regards  Gun-May

>Hi there

>have you tried using the FloatToStrF   function ?  this will allow you
>to format the result the way you want.
>for example....

>MyLabel.Caption := FloatToStrF(mynumber,fffixed,6,2);

>look up FloatToStrF in delpi help for all the options.

>hope this is of some use

Hi !

You can also use the following line:

Str(TheReal: TotalWidth: SignifDigits, TheString)

Str ( TheReal:4:2,TheString);

( :4:2 would give a number like 1000.00 )

Mojo

Other Threads