restricting decimal places on floating point values

Thread Solved
Reply

Join Date: Jul 2009
Posts: 17
Reputation: revski is an unknown quantity at this point 
Solved Threads: 0
revski revski is offline Offline
Newbie Poster

restricting decimal places on floating point values

 
0
  #1
Jul 5th, 2009
hi, just a quick question

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

Pascal and Delphi Syntax (Toggle Plain Text)
  1. VolumeCalc.Caption := FloatToStr(StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text));

thx for the help.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: Sub Xero is an unknown quantity at this point 
Solved Threads: 2
Sub Xero Sub Xero is offline Offline
Newbie Poster

Re: restricting decimal places on floating point values

 
0
  #2
Jul 5th, 2009
Use the Format command like this:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. VolumeCalc.Caption := Format('%.2f',[StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text)]);

Sub Xero
Last edited by Sub Xero; Jul 5th, 2009 at 4:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 17
Reputation: revski is an unknown quantity at this point 
Solved Threads: 0
revski revski is offline Offline
Newbie Poster

Re: restricting decimal places on floating point values

 
0
  #3
Jul 5th, 2009
thx for the help works great!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 17
Reputation: revski is an unknown quantity at this point 
Solved Threads: 0
revski revski is offline Offline
Newbie Poster

Re: restricting decimal places on floating point values

 
0
  #4
Jul 5th, 2009
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.

Pascal and Delphi Syntax (Toggle Plain Text)
  1. VolumeCalc.Text := FloatToStr(StrToFloat(EngineSizeVal.Text) / 2 / StrToFloat(CylNumVal.Text));
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 7
Reputation: Sub Xero is an unknown quantity at this point 
Solved Threads: 2
Sub Xero Sub Xero is offline Offline
Newbie Poster

Re: restricting decimal places on floating point values

 
0
  #5
Jul 5th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 17
Reputation: revski is an unknown quantity at this point 
Solved Threads: 0
revski revski is offline Offline
Newbie Poster

Re: restricting decimal places on floating point values

 
0
  #6
Jul 6th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC