DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Pascal and Delphi (http://www.daniweb.com/forums/forum124.html)
-   -   restricting decimal places on floating point values (http://www.daniweb.com/forums/thread201804.html)

revski Jul 5th, 2009 3:34 pm
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.

Sub Xero Jul 5th, 2009 4:26 pm
Re: restricting decimal places on floating point values
 
Use the Format command like this:
VolumeCalc.Caption := Format('%.2f',[StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text)]);

Sub Xero

revski Jul 5th, 2009 7:37 pm
Re: restricting decimal places on floating point values
 
thx for the help works great!

revski Jul 5th, 2009 8:35 pm
Re: restricting decimal places on floating point values
 
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));

Sub Xero Jul 5th, 2009 8:56 pm
Re: restricting decimal places on floating point values
 
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

revski Jul 6th, 2009 7:54 am
Re: restricting decimal places on floating point values
 
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


All times are GMT -4. The time now is 12:43 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC