on ‎2009 Sep 17 2:06 PM
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
Request clarification before answering.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
| User | Count |
|---|---|
| 9 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.