What is origin of dressed to the nines?

There are a few explanations for this phrase, but only theories as the origin in unknown. An example is that 9, being the highest single digit, symbolizes the best