Firstly you have to remove the comma(,) from string to convert or parse it in double or integer, otherwise it will give java.lang.NumberFormatException: Invalid double
or invalid integer. You can remove the comma(,) as,
String newNumberS = numberS.replace(",", "");
Above line convert 1,332.0
to 1332.0
. So, NumberFormatException solved. Now the whole working as,
String numberS = "1,332.0";
String numberE = "10";
try {
String newNumberS = numberS.replace(",", "");
double value = Double.parseDouble(nNumberS) * Double.parseDouble(numberE);
log.i("tag", "value: "+value);
} catch (NumberFormatException e) {
//catch exception here, if occur.
}
Now about difference between String.parseString()
, String.valueOf(object)
and Object.toString()
.
So simply if given string
is null String.valueOf(Object)
will prints NULL whereas Object.toString()
will throw NullPointerException
.