0

I am trying to convert a price amount 3,456 which is in string datatype to integer data type. But I'm getting a number format exception error. I have tried parseInt method and valueOf but giving same error.

public static void main(String[] args) {
String name="3,456";
int value= Integer.parseInt(name);
    System.out.println(value);
}

here is the error in console after running the code

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223

1 Answers1

0

Is the comma , mandatory in your data? Can't you leave it away? If the comma is really there, and those are really integers, just try name.replace(",","") to remove and then use parseInt on that.

Ralf Ulrich
  • 1,575
  • 9
  • 25