Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Re: String to Integer

Thread view: 
niki2481 - 15 Apr 2007 04:18 GMT
Hi, this may be a stupid question.  I am kind of new at java.  I am
trying to read in a number from a textfield that has to be string and
then take the number and do some adding and subtraction on the number
and return it back as a number to a textfield that is a string.  Is
there any one that could help.  I would be so greatful.

Niki
Tom Hawtin - 15 Apr 2007 04:25 GMT
> Hi, this may be a stupid question.  I am kind of new at java.  I am
> trying to read in a number from a textfield that has to be string and
> then take the number and do some adding and subtraction on the number
> and return it back as a number to a textfield that is a string.  Is
> there any one that could help.  I would be so greatful.

java.text.NumberFormat and DecimalFormat are the classes you want to
look at.

Tom Hawtin
Mich - 15 Apr 2007 05:46 GMT
>> Hi, this may be a stupid question.  I am kind of new at java.  I am
>> trying to read in a number from a textfield that has to be string and
[quoted text clipped - 6 lines]
>
> Tom Hawtin

When you convert from String to Integer also have a 'try' and 'catch' just
in case someone enters a letter ...
Muntasir Azam Khan - 15 Apr 2007 08:43 GMT
> Hi, this may be a stupid question.  I am kind of new at java.  I am
> trying to read in a number from a textfield that has to be string and
[quoted text clipped - 3 lines]
>
> Niki

To convert a String to an int use Integer.parseInt().
To convert to a float use Float.parseFloat().
To turn an int to a String: Integer.toString().

Muntasir
Faton Berisha - 16 Apr 2007 18:03 GMT
On Apr 15, 8:43 am, "Muntasir Azam Khan" <muntasir.k...@gmail.com>
wrote:

> To convert a String to an int use Integer.parseInt().
> To convert to a float use Float.parseFloat().
> To turn an int to a String: Integer.toString().
>
> Muntasir

Or, if you don't like static methods, you could do the same with,
e.g.,

int i = new Integer(s).intValue();
double d = new Double(s).doubleValue();
String str = i + "";

Faton Berisha


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.