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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit to 2 decimal places?

Status
Not open for further replies.

SpeedDemon

Programmer
Jan 1, 2001
70
GB
Hi all, im converting a floating value to a string before writing it out as a label.caption property. How can I quicly limit it to a maximum 2 decimal places??

Cheers
 
Specifies the precision. Check the help for details.
 
You also can use
Code:
FloatToStrF(floatValue, ffNumber, 18, 2)
, which does the same thing but with thousands separators; or
Code:
Format('Answer is %.2f', [floatValue])
Format() is approximately equivalent to sprintf() in C.

Just to confuse, there is also FloatToStr and FloatToText, but you usually don't want these. -- Doug Burbidge mailto:doug@ultrazone.com
 
Hi

Simply use the following
label.caption:=Formatfloat('0.00',yourfloatvariable);

simply relpace '0.00' with '0.000' etc to change number of decimal places you want
 
Hi all, cheers for responses. I ednded up using the FloatToStrF() and the ffCurrency property.

Thanks all!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top