Check the actual bag dimensions and closure type first. A cheap bag you have to double up may change the comparison.
For a box of 40 at eight dollars, divide eight by forty to get 20 cents per bag. Repeat with the second box using its own count.
Write both figures on the shopping list. If you are trying a new fit, buy a small box before committing to a large pack.