954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

restricting decimal places on floating point values

hi, just a quick question

can somebody please tell me how to restrict the output of the code below to 2 decimal places.

VolumeCalc.Caption := FloatToStr(StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text));


thx for the help.

revski
Light Poster
28 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Use the Format command like this:

VolumeCalc.Caption := Format('%.2f',[StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text)]);


Sub Xero

Sub Xero
Newbie Poster
7 posts since Jul 2009
Reputation Points: 10
Solved Threads: 2
 

thx for the help works great!

revski
Light Poster
28 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

i have just changed my Label to a EditBox.. and the above code doesnt seem to work at all, just wondering how to limit an edit box to 2 decimal places.

VolumeCalc.Text := FloatToStr(StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text));
revski
Light Poster
28 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

It should be exactly the same. Format returns a string, so there's no difference in applying the result to an Editbox or a label.
What exactly is the problem?

Sub Xero

Sub Xero
Newbie Poster
7 posts since Jul 2009
Reputation Points: 10
Solved Threads: 2
 

dont matter, had a bit too much to drink last night :/

format is working fine, sorry about wasting your time asking again.

thx for the help

revski
Light Poster
28 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You