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
> 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 ...
> 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