By definition, P and NP are (infinite) sets of decision problems (more exactly, Languages, but let's keep it simple). Studying the decision problem version of computational problem is simpler, always provides good information about lower bounds on their computational complexity, and often provides good information about upper bound on their computational complexity. It is such a basic technique that experienced researchers switch without effort from one version to the others (such as in the answers on SE).
There are standard techniques for transforming function and
optimization problems into decision problems (see the Optimization problems section of the Wikipedia page on Decision Problems): Given an optimization problem $O$, the corresponding decision problem $D$ would be to decide if, for a given instance $I$ and a threshold $t$, the score of an optimal solution $OPT_O(I)$ is larger than the threshold $t$, i.e. if $OPT_O(I)>t$.
The time complexity of $O$ and $D$ are interdependent:
Any solution to $O$ running in time polynomial in the input size yields a solution for $D$ running in time polynomial in the input size (basically, the same time plus that for one single operation, a comparison), by just finding the optimal value and comparing it to the threshold $t$.
Given a solution $S$ running in time polynomial in the input size to the decision problem $D$ with threshold $t$, one can perform an Exponential Search for the value $OPT$ in $2\log_2(OPT)$ comparisons, where $S$ is used for each comparisons. This results into an algorithm finding $OPT$ in time polynomial in the input size even if $OPT$ is exponential in the input size as the running time is a polynomial multiplied by another polynomial ($\log_2(OPT)$).
I hope it helps!