I have a
String with a
double number. Unfortunately, the number is created on backends with different locals, so it could be both 101.02 and 101,02 (different delimiters). I need to get the position of this delimiter if it exists and get 0, if it is not.
I've come to two options:
int pos = amount.indexOf(',') == -1 ? (amount.indexOf('.') == -1 ? 0 : amount.indexOf('.')) : amount.indexOf(',');
Second option with the same logic but different style:
int pos = amount.indexOf(','); if (pos == -1) pos = amount.indexOf('.'); if (pos == -1) pos = 0;
I do not need to have a
double number from
String, I just need the position of the delimiter to color the
String (using the Android class
Is there a cleaner way to achieve this goal? And which of these styles are better, in your opinion? Is there some way to use the
DecimalFormat class to achieve the goal?