2006 Kia spectra ex

The speedometer and odometer recently stopped working some of the time. The odometer is digital and still has power, but doesn’t count miles. Again, at times it’s fine, others, it doesnt. What could be the problem and estimated cost for repair?