It is surprising how often they are cheaper. I was ordering some glue, decided to double check the price, I could drive for 30 minutes and buy local, and pay more or order it for cheaper from Amazon. I didn't need it the same day so getting it tomorrow didn't matter. Amazon also sells everything need some M2 screws Amazon will have them, no idea where to buy something like that locally Home Depot won't carry them.
The proper comparison isn't Amazon vs local, it's Amazon vs other web shops (likely with more traditional supply chains) - especially for items that are only ever going to be part of a wide selection like M2 screws. HomeDepot.com and Lowes.com have M2 screws, as well as Zoro, McMaster, or other specialty web shops [0]. My specific go-to for one-off [1] screws is usually Zoro, as I usually prefer stainless (or grade 8 for larger sizes).
[0] I had been fond of "Albany County Fasteners" but I've soured as they've gradually jacked up the prices while removing free shipping. I don't even like free shipping, but it is a way for ordering to be more convenient as it prevents me from wanting to sit on an order for a while to batch it up.
[1] as opposed to stocking up on an assortment