Gold ends at a nearly 3-month high as dollar weakens