This is the kind of thing that (expensive) ERP/inventory management systems will handle for you. As I've designed such systems in the past I'll try to explain a simple version of the kind of approach that we'd use.
For Bookkeeping purposes try not to think about the unit cost of the items at all (obviously you still think about them for sales purposes so that you know what your profits are). Instead consider the total cost of the items that you've bought (which should always be an exact number of pennies) and whenever you sell an item (or items) you remove the cost of the proportion of the total that you've sold, rounded to the nearest penny.
Example you buy 20 items for $100, which is £60.42
You sell one for 60.42/20 = £3.02
Now you have 19 totalling 57.40
You sell another 18 for £54.38 (57.4 x 18 / 19) Some of those sold for 3.02 and some sold for 3.03, the averaging method automatically costs each one appropriately as you sell it.
This leaves 1 in stock worth £3.02
This method automatically rolls up rounding errors on sale into the cost of future sales.
Whenever you make further purchases of the same product the simple way of dealing with that is to add the quantity and value of the new purchase to your existing stock total, so that if the buying price has changed the new purchases "mix" with the old ones to effectively produce a new average price. Alternatively you can keep each purchase separate in the books so that the cost price changes whenever you start selling a new batch.
Whether or not you think it is worth it to calculate average cost in that way each time you sell something is another matter of course. It is easy if you have software doing it for you but I don't know how people get on with this stuff manually.
I guess that the accountants might suggest assigning an average and consistent cost to the items in exact pennies, even if this doesn't multiply up to the true stock value. Then, periodically you do a stocktake which will come to a different value to the value in the books because of accumulated rounding errors, and you write that whole adjustment into the books at once, as a stocktaking adjustment.