J Boonders
J Boonders

Reputation: 41

How do I see if a double contains a given integer number?

I am attempting to find a given integer in a double. I tried the code return String.valueOf(number).contains(digit); but received an error saying:

int can not be converted to CharSequence.

Can someone help me fix this? Or is there a different line of code that does essentially the same thing?

Full code

//This method returns true if the double number contains the int digit
//for example, 1.123231312313 does not contain 4, but it does contain 3
public static boolean containsDigit(double number, int digit) {
    return String.valueOf(number).contains(digit);
}

Upvotes: 1

Views: 668

Answers (1)

Eymeric G
Eymeric G

Reputation: 53

return String.valueOf(number).contains(String.valueOf(digit));

Just as the error says you're trying to give the contains function an int

Upvotes: 2

Related Questions