When a company wants a new piece of software made for them, they write (or hire a consultancy to write) a requirements specification. This document lays out what the software is supposed to do, where it is supposed to be installed, what software, hardware, users, and other things it is to interact with.
A diligently written requirements specification makes it possible for any programming company to give a precise price quote. It also contains functionality descriptions that can (and invariably will) be used to decide whether the software meets the specification.
Although the investment in time, money and staff can seem expensive, it should be remembered that all the things in a requirements specification have to be found out or decided upon during programming anyway. This means that if there is no requirements specification before programming starts, then all the same issues will have to be confronted during development. At the minimum this takes equal time and money as writing the requirements specification in the first place. Normally, however, this costs far more because parts already written may be incompatible with new findings or decisions that have to be made.