I've been in the industry for about 3 years now and still get to situations where I end up working much more than I initially planned. Everything would be OK if those projects wouldn't have a fixed price.
Most of the time I'm just too optimistic and when i think something would take 1 hour it takes 3 for example.
I even came up with formulas like: (my estimation in hours + (initial estimation in hours / 3 ) (for bug fixing)) * 2)
But it still fails. Most of the time I undercharge.
How do you do it? How to convince a client to work with a hourly rate instead of fixed?