Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Vogel612
Created May 22, 2015 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vogel612/1ceee5e47234b1c1a53f to your computer and use it in GitHub Desktop.
Save Vogel612/1ceee5e47234b1c1a53f to your computer and use it in GitHub Desktop.
private static String transformFloatingPoint(final String floatingNumber) {
int floatingPointIndex = floatingNumber.lastIndexOf('.');
if (floatingPointIndex == -1 || floatingPointIndex < floatingNumber.lastIndexOf(',')) {
floatingPointIndex = floatingNumber.lastIndexOf(',');
}
if (floatingPointIndex == -1) {
// no floating point exists
return floatingNumber;
}
final int floatingPointPositionFromEnd = floatingNumber.length() - floatingPointIndex;
StringBuilder result = new StringBuilder(floatingNumber.replace(",", "").replace(".", ""));
final int newFloatingPointIndex = result.length() - floatingPointPositionFromEnd + 1;
result.replace(newFloatingPointIndex, newFloatingPointIndex, ".");
return result.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment