cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Converting Float to Int

Former Member
0 Likes
6,563

HI,

How could I convert float value to Int and pass ? I am using UDF ..

Eg:

11:9999999 I want to pass 12, Its a run time Program so dont know how the value would be...

Is there any function to round it off?

Thanks

Rajeev

View Entire Topic
Former Member
0 Likes

just assaign 11.9999999 to int variable

int value =11.9999999;

then value will be equal to 12

if you want to return this int value from a UDF then assaign value to String variable as

String res=value+"";

return res;

Former Member
0 Likes

Hi Guys,

I am unable to convert float to int.. I tried wtih all the mentioned syntax but there is some error in UDF..

UDF will give result as a value or null so I need to convert with in the code itself..

How can I convert 11.99999 to 12

there aer 4 values which needs to be divided and the result to be passed..

Is there any round function so that I can convert this value to nearest highest value with in the UDF?

Any inputs

Rajeev

Edited by: rajeev raj on Sep 17, 2009 5:06 PM

Former Member
0 Likes

Hi Rajeev,

We have a standard ceil function in airthmetic functions. You can use that for your current issue. You have also round function in airhtmetic, if you want that you can use it. No udf is required for this.

Regards,

---Satish

Former Member
0 Likes

Hi Rajeev,

If your issue doesnot solve with standard functions then you can write this udf. Create a value udf with one input argument 'a'.

Imports: java.*;

// Add this code:

float f = Float.valueOf(a.trim()).floatValue(); //Udf will only take string as input this line will convert the input as into float value

int b;

b = (int) f; //convert float to int in this line

String s = String.valueOf(b); //converting the int to string for output

return s; //returning back the ouput.

So if input is 11.9999 the output is 12.

Regards,

---Satish

Former Member
0 Likes

Thank You ALL,

I got it resolved by just adding the following line in my UDF

int i = (int)Math.rint(my float variable);

Thanks Saptak, Points awarded.

Thanks once again.