Board index » delphi » Displaying real numbers

Displaying real numbers

Hello,
I am trying to display a real number in a label to a certan number of
decimal places. But, my feeble attempts at deciphering the help menu has
failed. Can anyone help me. I would be most grateful.
Cheers,
Mark
 

Re:Displaying real numbers


On Mon, 20 Aug 2001 19:56:55 +0100, "Mark" <markge...@hotmail.com>
wrote:

Quote
>I am trying to display a real number in a label to a certan number of
>decimal places. But, my feeble attempts at deciphering the help menu has
>failed. Can anyone help me. I would be most grateful.

Check out the FormatFloat function.

Re:Displaying real numbers


In article <3b815c5...@mk-nntp-1.news.uk.worldonline.com>, "Mark"

Quote
<markge...@hotmail.com> writes:
>I am trying to display a real number in a label to a certan number of
>decimal places. But, my feeble attempts at deciphering the help menu has
>failed. Can anyone help me. I would be most grateful.

Format is the best to use for all formatting when you will not get any errors,
and it is easy to add additional text ...

MyFloat := 23.45678;
YourFloat := 0.083;

Label1.Caption := Format('%.3f', [MyFloat]); // displays"23.456"

Label1.Caption := Format('%8.3f', [MyFloat]); // displays "xx23.456" x == space

Label1,Caption := Format('MyFloat value is %.5f%sYourFloat value is %3f',
[MyFloat, #13, YourFloat]);
// displays ...
"MyFloat value is 23.45678
YourFloat value is 0.083"

Note that ...
"%" is a format definition prefix
"f" is the type of input (float) and the end of the format definition
"s" is for a string input (#13)
the figure before the point is the minimum width of the output
the figure after the point is the number of decimal places in the output.

For integer type of input use a "d" (integer decimal string output) or an "x"
(hex string output).

Look up "Format strings" in help.

Alan Lloyd
alangll...@aol.com

Other Threads