In most programming languages, integer and real (or float, rational, whatever) types are usually disjoint; 2 is not the same as 2.0 (although most languages do an automatic conversion when necessary). In addition to technical reasons, this separation makes sense -- you use them for quite different purposes.

Why did they choose to say $\mathbb{Z} \subset \mathbb{R}$ in math? In other words, why are 2 and 2.0 considered the same?

When you are working in $\mathbb{R}$, does it make any difference whether some elements, eg. 2.0, also belong to $\mathbb{Z}$ or not?


If you want to do things very formally, the integers are in fact not a subset of the reals: they are entirely different constructs (which I guess is more or less what you are saying in your question). However, the reals do contain the set $$\{\,\ldots,\,-2.0,\,-1.0,\,0.0,\,1.0,\,\ldots\,\}$$ which "looks just like" the integers. The usual terminology is that the sets are isomorphic. If you take any true statement in the arithmetic of integers, and replace each integer by the corresponding real number, the result will be a true statement about the real numbers. For example, the statement $$2+3=5$$ corresponds to $$2.0+3.0=5.0\ .$$


Formally speaking, this depends on the context.

Sometimes it's nice to have everything as a subset. It's easy to have that an integer is a real number, since it allows us to talk about the subspace topology, and that the operations coincide with what we expect them to be.

Sometimes it's not as nice, in which case we prefer to talk about "embedding", namely there is an embedding (which is unique up to some properties preserved) which identifies a subset of the real numbers with the integers.

If you want to build things from the ground up, then you're right. You build the natural numbers, then you build the integers and then the rationals and finally the real numbers (and you can continue). Each step comes with some canonical embedding, which we can then extend and have a canonical way to identify the natural numbers with a subset of the real numbers, and so on.

But sometimes it's nicer to say "Okay, now that we have $\Bbb R$ and all those canonical subsets which behave like $\Bbb{N,Z,Q}$ and so on, let's redefine them as these subsets." now we can talk about subspaces directly and subrings and subfields and so on and so forth.

Similarly you might want to have $\Bbb R$ as a subset of $\Bbb C$, and sometimes as a subspace (and therefore a subset) of $\Bbb R^3$; and sometimes you will want to have these objects separated as "different types", and keep track on the embeddings.

If you want to focus on the example of $2$, then note that $\Bbb Z$ and $\Bbb Q$ and $\Bbb R$ are all rings (whatever that means) which has a unit, and $1$ is that unit, so each has a version of $1$ and $2$ is defined as a shorthand for $1+1$. Does it matter where you do this addition? No, it doesn't, since the term $1+1$ is syntactical in the language of rings, and will have similar properties in $\Bbb Q$ and $\Bbb R$, and the same properties in $\Bbb Z$. Since it doesn't matter for the basic properties of $2$ in which of these rings we consider it, we can just think about those rings coincide on these numbers.