# Solved: Converting string to integer



## GUSMAN (Dec 19, 2001)

Hi
I have a programme that basically looks for an account number and password in an access database and if there is a match it opens a window showing the account number, surname, forename and balance relating to that account.

So lets say for example I have £200 in my account, it will display as 200.0000.I need to convert it to an integer I think so it will display properly.

Now I have to do a withdraw or deposit function to either deduct or add to that £200 but I 
keep getting an error when I try it.

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "200.0000"

Is this down to the same problem?

Do I just need to somehow convert the label the amount is showing in to integer??

really lost on this one

Cheers

Gus


----------



## covert215 (Apr 22, 2006)

in java, just use parseInt(###);
where ### is your string

however, you should probably use DecimalFormat if you know how to make it seem like money


----------



## GUSMAN (Dec 19, 2001)

Where do I put that bit of code?

This is the snippet of code that says to display the balance from the database in the balance text field:

try
{
conObject = DriverManager.getConnection(URL,name,password);
statObject = conObject.createStatement();
ResultSet statResult = statObject.executeQuery(SQLQuery);
while ((statResult.next()) && (!found))
{
AccText = statResult.getString(1);
if (AccText.equals(IDNum))

{
Firstname.setText(statResult.getString(2));
Surname.setText(statResult.getString(3));
Balance.setText(statResult.getString(4));// this is where it is told to display in the balance text field }
}

Is it somewhere around there?

Much app

Gus


----------



## Chicon (Jul 29, 2004)

```
[SIZE=3]
   try {
      String test = statResult.getString(4);
      int val = Integer.parseInt(test);
   }
   catch(NumberFormatException nfe) {
   // some statements if the value of the string is not numeric, for example :
      System.out.println(nfe.getMessage());
   }[/SIZE]
```


----------



## reneNaduya (May 5, 2006)

200.0000 is a double. You can't assign that to an int.

Try this:

```
Double.parseDouble(Balance.getText()); // this will return a double 
                                       // assuming that the text in the 
                                       // Balance label is numeric.
```


----------



## GUSMAN (Dec 19, 2001)

Cheers Rene

That was what I was after

Thanks to all for the replies

Gus


----------

