Question: I have a `String` value which can either hold a `Long` or a `Double`. The `String` may be `Locale` based. 

So it may hold the following values:

```
11
11.00
15,25 (for Locale like Denmark where the decimal part is denoted by a comma instead of dot)

```

I want to do something only when it is a Double; in sense that it contains a fraction value. A fraction value of "00" is also a valid case.

```
if(string contains fraction){
  // do something
}

```

Given above three examples, control should go inside `if` for `11.00` and `15,25` but not for 11. 

How can I check this? 

Please keep in mind that Locale is involved. So dot and comma may have different meaning for different Locale. So simple regex to find their occurrence won't work. For e.g. 11,00 is 1100 if Locale is Australia and thus is not a double. But 11,00 is a double if Locale is a European country like Denmark or Germany.

I need to find some solution using `NumberFormat` but not able to work it out. 

I have Locale info. So I know if the String is of which Locale. Given that, how can I find if String has a fraction or not?

Answer: 
With a regex you could do

```
Pattern decimalPattern = Pattern.compile("\\d+(,|\\.)\\d+{2}");

```

and then have 

```
boolean isDecimal = decimalPattern.matcher(input).matches();

```

Regex:

* `\d+` one or more digits
* `(,|\\.)` a decimal point or a comma
* `\d+` one or more digits again

Or you could do the splitting thing

```
String[] split = input.split("(,|\\.)");
boolean isDecimal = split.length > 1 && split[1].length() == 2;

```
You could use a loop to check if it have a comma or dot and then check with the if?

```
boolean IsADouble = false;
for (int i = 0; i < String.length(); i++) {
            if (String.charAt(i) == ','|| String.charAt(i) == '.') {
                IsADouble = true
            }
        }

```

And then you create the If to do something if its a double.

Hope it helped you :)