cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion from String to Number

Former Member
0 Kudos

Hi All,

Can you please provide me the UDF for the conversion from string to the number?

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Swetha,

i think you have posted same thread few days back,and we have provided solution i guess..?? it is not working out??

where you struck exactly.??

Regards,

Raj

Former Member
0 Kudos

Hi Raja,

Thanks for the reply.

I have written the following UDF with the argument as input but it is giving the error with the empty processing log

Input Variable = String input

input=input.replaceAll(" ","");

// checking for null or spaces,if found return 0

if ((input.length() == 0) || ( input == "") )

return ""+0;

else{

Integer x = new Integer(input);

return x.toString();

}

Can you please help me?

Thanks in advance.

rajasekhar_reddy14
Active Contributor
0 Kudos

Try this code,

pass your string value as a string argument,just say valriable name Str1

int Str2 = Integer.parseInt(Str1);

return Str2;

above two lines of code enought.

Regards,

Raj

Former Member
0 Kudos

Hi Raja,

I used the UDF and passed the argument as Str1 type String,

But I got the following error

incompatible types found : int required: java.lang.String return Str2;

Can you please help me?

Thanks in advance

Former Member
0 Kudos

Hi,

Use like this

int Str2 = Integer.parseInt(Str1);

return ""+Str2;

But i wonder y u req this UDF... taking string.. converting to int... returning as again a string...

Babu

Edited by: hlbabu123 on Jul 26, 2010 12:12 PM

Former Member
0 Kudos

Hi Swetha,

Please use the Function below to get the result :

//--- Utility function to get int using a dialog.

public static int getInt(String mess) {

int val;

while (true) { // loop until we get a valid int

String s = JOptionPane.showInputDialog(null, mess);

try {

val = Integer.parseInt(s);

break; // exit loop with valid int >>>>>>>>>>>>>>>>>>>>>>

}catch (NumberFormatException nx) {

JOptionPane.showMessageDialog(null, "Enter valid integer");

}

}

return val;

}//end getInt

I have not tested the function ,so just let me know if it is working or not.

Regards

Ravi Anand

Former Member
0 Kudos

Hi Shweta,

Use this below one line code, that's enough.

return (Integer.parseInt(str1)); // Here str1 is the input variable.

Regards

Ramesh

rajasekhar_reddy14
Active Contributor
0 Kudos

try with babu code just add ""+ to retun statement,i have tsetd this one working fine.

Former Member
0 Kudos

Hi Venkataramesh and Raja,

Thanks for your reply.

Answers (1)

Answers (1)

Former Member
0 Kudos

answered