How can I convert String to numeric and numeric to String with Java??
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pedro_Palomo
Posted On:   Wednesday, February 6, 2002 04:39 AM

Hi friends of jguru¡¡¡

How can I convert String to numeric and numeric to String with Java??

I need both conversions, but i don't Known what methos i have to use.

Thanks and my best regards¡¡

Pedro. Spain.

Re: How can I convert String to numeric and numeric to String with Java??

Posted By:   Chinmay_Bajikar  
Posted On:   Wednesday, February 6, 2002 08:18 PM

Java language provides wrapper classes like Integer,Float,etc.

(note the difference between the prmitive type names and the class names)

in the java.lang package.

U can use these classes to convert from String types to the

respective numeric format u want to, using the static parsexxxx()

methods provided in these classes.


ex Integer.parseInt(String s), Float.parseFloat(String s), etc.



As far as conversion of numbers to Strings is concerned, u can do it in several ways.

But the most proper way to do it is the valueOf() static methodd of the String class

which has been overloaded to accept many types of data.

for that matter we even have,the toString() method defined in the

Object class.(from which all the other classes in java are derived)

So all the objects have this method avaiable to them and can be called

as per requirements



Please refer to the Java documentation for more detailed and complete information


Bye and wish that the info helps you,

Chinmay,India

Re: How can I convert String to numeric and numeric to String with Java??

Posted By:   Anonymous  
Posted On:   Wednesday, February 6, 2002 05:15 AM

Integer.parseInt(str) and String.valueOf(i)
About | Sitemap | Contact