When does the decimal representation of 1/d terminate?

Consider the number $\frac{1}{d} \in \mathbb{R}$ for $d \in \mathbb{N}$, and in particular, its decimal representation. For example, $\frac{1}{2} = 0.5, \frac{1}{3} = 0.\bar{3}, \frac{1}{4} = 0.25$, etc. Notice that in some cases the decimal representation of $\frac{1}{d}$ terminates (e.g. $\frac{1}{5} = 0.2$), and in some case it is infinitely long (e.g. $\frac{1}{9} = 0.\bar{1}$). For a particular $d$, can we tell when the decimal representation of $\frac{1}{d}$ terminates, versus when it is infinitely long? This question came up after a night of poker between me and some friends, in the context of problem #26 from Project Euler. One of my friends claimed that if the prime factors of $d$ are limited to $2$ and $5$ (i.e. one, the other, or both), then the decimal representation of $\frac{1}{d}$ will terminate. Upon a moment of reflection, he also claimed that the converse is true: if $d$ has a prime factor other than $2$ and $5$, then the decimal representation of $\fr...