# Possible to convert float to int ?

Hi,

I would like to know if it is possible to do something like:

int var1
float var2

var2=20;
var1=var2*2;

In C/C++, this can be done by:
var1=(int)var2*2;

I can’t do it for AnyScript–where var1 and var2 are system defined
variables… anyway to go around this?

Thanks,
Leng-Feng

Hi Leng-Feng

Yes this is possible, you can use either floor, ciel or round.

Floor function will take the nearest lower integer
Ciel function will take the nearest upper integer
Round function will round of the number in a clever way

This is an example on how to use the functions:

AnyFloat A1=20;
AnyInt A2=round(A1*2.575);//mult. gives 51.5, it will return 52

AnyFloat B1=20;
AnyInt B2=ceil(B1*2.575); //mult. gives 51.5, it will return 52

AnyFloat C1=20;
AnyInt C2=floor(C1*2.575);//mult. gives 51.5, it will return 51

AnyBody Support

— In anyscript@yahoogroups.com, “Leng-Feng Lee” <lengfenglee@…>
wrote:
>
> Hi,
>
> I would like to know if it is possible to do something like:
>
> int var1
> float var2
>
> var2=20;
> var1=var22;
>
> In C/C++, this can be done by:
> var1=(int)var2
2;
>
> I can’t do it for AnyScript–where var1 and var2 are system defined
> variables… anyway to go around this?
>
>
> Thanks,
> Leng-Feng
>