Skip to main content
Fixed wording ambiguity as mentioned by Jon Skeet in http://stackoverflow.com/questions/12734721/string-replace-not-replacing-characters
Source Link
Joe
  • 48k
  • 37
  • 166
  • 261

You need to make your string actually equalassign the changes you makenew value back to the string or they are lostvariable.

double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176 System.out.println(myDouble); String myDoubleString = "" + myDouble; System.out.println(myDoubleString); myDoubleString = myDoubleString.replace(".", ","); System.out.println(myDoubleString); myDoubleString = myDoubleString.replace('.', ','); System.out.println(myDoubleString); 

You need to make your string actually equal the changes you make to the string or they are lost.

double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176 System.out.println(myDouble); String myDoubleString = "" + myDouble; System.out.println(myDoubleString); myDoubleString = myDoubleString.replace(".", ","); System.out.println(myDoubleString); myDoubleString = myDoubleString.replace('.', ','); System.out.println(myDoubleString); 

You need to assign the new value back to the variable.

double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176 System.out.println(myDouble); String myDoubleString = "" + myDouble; System.out.println(myDoubleString); myDoubleString = myDoubleString.replace(".", ","); System.out.println(myDoubleString); myDoubleString = myDoubleString.replace('.', ','); System.out.println(myDoubleString); 
Source Link
AlbertoPL
  • 11.5k
  • 5
  • 51
  • 73

You need to make your string actually equal the changes you make to the string or they are lost.

double myDouble = myObject.getDoubleMethod(); // returns 38.1882352941176 System.out.println(myDouble); String myDoubleString = "" + myDouble; System.out.println(myDoubleString); myDoubleString = myDoubleString.replace(".", ","); System.out.println(myDoubleString); myDoubleString = myDoubleString.replace('.', ','); System.out.println(myDoubleString);