The correct length of a chain is irrelevant at purchase since they all come at a set length. (Usually 114 1/2" links, sometimes 120 1/2" links). In special cases, like tandems and recumbents, you may need to join 2 chains to have enough length.
Sizing a chain to length for a particular bike is a set process. It does vary a bit.
In the case of an IGH bike, which for this purpose is essentially a single speed, set the rear wheel in the dropouts of your frame, leaving the axle nuts or quick release loose, with the wheel all the way forward in the dropout. (Bikes with concentric bottom brackets should be in the most relaxed position available.)
Wrap the uncut chain around both the chainring and the rear cog. Find the place where the chain meets with no slack. Mark that link, being careful to make sure you pay attention to the outer plates, and have a set of inner plates to pin through them. Add 2 links to this marked length, to give yourself slack to adjust the chain tension, and cut the chain. Rivet the chain together using the link, pin or rivet which the brand of chain requires.
Derailleur geared bikes use a similar method, except that you wrap the chain around the large front chainring, and the large rear cog without going through the derailleur. Adding the 2 links here gives the appropriate amount of slack for the derailleur to operate.
And that's how you do it. There are diagrams on the rear derailleur manual pages, which I'll add when I'm not on the mobile site.