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!

casting, parsing, or any other way

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
GB
i want to do the sum 'A / 2.55' where A is an integer, and i want the result as an integer. delphi sees 2.55 as an extened type. i presume i need to convert the A to extended, then the result to an integer. something like:

(java)Integer.parseInt(Float.parseFloat(I)/2.55);

how do i do this in delphi though?


ps - my current code looks like this:

ProgressBar1.Position := A/255;
 
hi

ProgressBar1.Position := trunc(A/255);

Trunc gives the mantissa part of a real. Frac() would give the fraction part.

lou

 
oops, mantissa is the fractional part, sorry.

Trunc gives the integer part of a real. Apologies for any confusion...I was trying to use flash words and failed [blush]. I think the word is magnitude but still I could be wrong.

Basically, you need Trunc().

right, I'm gone...

 
The division A/2.55 gives a real (extended) result, and so does Int(A/2.55). You need to use Trunc(A/2.55) to truncate the real to an integer.
 
Just thought...

You could use:-

ProgressBar1.Position := A [blue]div[/blue] 255;

Div gives the integer division and

A mod 255 would give remainder as an integer.

lou

 
I was going to suggest div but you can't use it if the divisor is a real number. Perhaps seanbo could clarify whether the divisor is 255 or 2.55? If 255 then use div, if 2.55 then use trunc.

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Thanks Zathras, you are right - interesting site that, got me thinking... cor I'm quite exhausted now.

Thanks to Clive too.

 
I usually use something like
Code:
  ProgressBar1.Position := ( A * 100 ) div 255;
in these circumstances.

Andrew


 
But, back to the original question?

seanbo, if the intent is to display a progress bar, why not just set the Max property to 255 and use this code:
[blue]
Code:
  ProgressBar1.Position := A;
[/color]

(Let Delphi take care of the math.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top