Board index » delphi » Float To Int / Int To Float

Float To Int / Int To Float

I am trying to do some maths (sin & cos) on the position of a form on the
screen. The form postions (TForm1.left etc.) are Integers and Sin() uses
Floating point numbers. I cannot find an obvious way of converting the
Integer into a Real so I can use the maths function on it. I think I could
do StrToFloat(IntToStr(intval)), but that seems a very clumsy way of doing
it!

 

Re:Float To Int / Int To Float


You can feed an integer to any function that need a float-inputvar.
If the output is a float, you can use Roud or Trunc to cast it to an
integer.

Alfred.

"David Wilbourn" <d.wilbo...@chello.nl> schreef in bericht
news:fndx7.42619$Z97.1465557@Flipper...

Quote

> I am trying to do some maths (sin & cos) on the position of a form on the
> screen. The form postions (TForm1.left etc.) are Integers and Sin() uses
> Floating point numbers. I cannot find an obvious way of converting the
> Integer into a Real so I can use the maths function on it. I think I could
> do StrToFloat(IntToStr(intval)), but that seems a very clumsy way of doing
> it!

Re:Float To Int / Int To Float


Quote
David Wilbourn <d.wilbo...@chello.nl> wrote:
> I am trying to do some maths (sin & cos) on the position of a form on the
> screen. The form postions (TForm1.left etc.) are Integers and Sin() uses
> Floating point numbers. I cannot find an obvious way of converting the
> Integer into a Real so I can use the maths function on it. I think I could
> do StrToFloat(IntToStr(intval)), but that seems a very clumsy way of doing
> it!

Hi,

I would be very careful in passing an normal integer value into the Sin()
function of MATH. The help says that sine and cosine function dont need the
values in degrees (integers) but in radians (floats). So first convert your
position values into radians using

    (pos * 180) / Pi

and use the returned value as parameter in the sine and cosine function. The
returned value is the correct result and can be used further on.

cu,
Toralf

Other Threads