There are a number of theories here, and apparently no widely accepted single one on the origin of the phrase.
Some think in modern times that it is mostly used as a rating scale (1-10), meaning 99999... Infinitely as close to perfect as possible. Other theories have ranged from originating from Old English, "dressed to the eyes", which apparently would have been expressed as "to then eyes"-- but there are some problems with dates or origin there.
It seems there is no definitive answer, but here is a website where you can read some of the other theories.
To the Nines
Some think in modern times that it is mostly used as a rating scale (1-10), meaning 99999... Infinitely as close to perfect as possible. Other theories have ranged from originating from Old English, "dressed to the eyes", which apparently would have been expressed as "to then eyes"-- but there are some problems with dates or origin there.
It seems there is no definitive answer, but here is a website where you can read some of the other theories.
To the Nines