For gases, the density is obtained by using an equation of state.
An equation of state relates the molar density (or specific molar volume) of a fluid (so they sometimes work for liquids, too!) to the temperature and pressure of the fluid.
simplest -> ideal gas law (PV=nRT)!
The ideal gas law may also be written as $P \dotV =\dot n RT$ for a flowing system or $P \hat V = RT$, where $\hat V$ is the specific molar volume.
The ideal gas law is an approximation (!) that has only limited applicability. It is usually used for diatomic gas when (RT/P)>5 L/mol and for other gases when (RT/P) > 20 L/mol (i.e., at high specific volumes!).
A technique for dealing with ideal gases that is of dubious utility is to utilize the reference point of standard temperature and pressure.
STP is an arbitrary reference point chosen to be T = 273K (0C) and P = 1 atm.
Use the ideal gas law to determine P, V, or T of a single component