How was the value of gold and silver determined back when it was used for currency?

Which is why coins started being made with reeded (grooved or milled) edges:

Reeded edges are often referred to as “ridged” or “grooved” (US usage), or “milled” (UK usage).[1] Some coins, such as United States quarters and dimes, have reeded edges. Reeding of edges was introduced to prevent coin clipping and counterfeiting.[2][3]

Wikipedia