Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a double value

Status
Not open for further replies.

Morelos

MIS
Apr 12, 2000
33
MX
I want to display a numeric value on an edit box, but since my variables are DOUBLE, so is my result, so the text displayed on the edit box is 15 digits long on the right side of the decimal point. I only need 4 decimal digits not 15 for display purposes. I know there are a few formatting functions but I don't know exactly which one and the correct syntax.

Eg.:
var value1:double;
Value1:=102.50*1.50;
edit1:=floattostr(value1);

so I want to display 153.7500 in the edit box
...NOT 153.751236475895969

THANKS
ROB.
 
You want something like this:
Code:
  Edit1.Text := Format('%7.4f', [Value1]);
Look up the "Format" function in the help file. There's a lot more to it than I have indicated here.
 
I'm not near Delphi but I believe there is one called FormatFloat and a call to it looks something like this, if my memory serves me correctly:
Code:
Edit1.Text := FormatFloat('0.0000', Value1);
You need to check the return type as I can't remember if it returns a string or not.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top