Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 16
Registered: ‎01-22-2013
My Device: Blackberry9800
My Carrier: JAZZ

String to Int Conversion

I am working on an application in which i want ot convert String into int.. i have made a method which wil return String, but it is not wokring properly.. Kindly help me out,i want to return answer in String after conversion...


public class MainClass
{
private static double res=0;
public static void main(String args[])
{
//System.out.println("abcdefegfskdj");
converter();
}

public static String converter()
{
String prevValue = "100";
String updatedValue = "50";

 

double pv = Double.parseDouble(prevValue);
double uv = Double.parseDouble(updatedValue);

res= pv-uv;
prevValue = Double.toString(res);

 

System.out.println(res);
System.out.println("res");
System.out.println(prevValue);
System.out.println("end");

return prevValue;

}

}

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: String to Int Conversion

Hi @khalidhabib

 

To convert from String to int, just use: "Integer.parseInt(String)".

 

To convert from primitive to String, use "String.valueOf(your_value)".

 

E.

New Developer
Posts: 9
Registered: ‎03-04-2013
My Device: 9320
My Carrier: Airtel

Re: String to Int Conversion

Simply use as mentioned by Maadani, String.valueOf(int_value)
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: String to Int Conversion

I believe someone did the analysis of the byte codes and

String.valueOf(int_value)

actually turns into

Integer.toString(int_value)

so that is what I use....