Put both cartons on the same footing: what would a dozen eggs cost? A dozen for $3.60 works out to 30 cents an egg. An 18 count carton for $5.04 works out to 28 cents an egg, or $3.36 per dozen. The larger carton saves 24 cents per dozen, but you still need another $1.44 at checkout.
At a farm stand, try asking, “How many eggs come at that price?” and “If I bring a carton back next time, can you use it?” That second question is worth asking before you save a stack of empties.
Search “price per egg calculator” to compare other carton sizes. Then pick the amount your household will actually use.