Let K be a rationally null-homologous knot in a 3-manifold Y , equipped with a nonzero framing , and let Y .K/ denote the result of -framed surgery on Y . Ozsváth and Szabó gave a formula for the Heegaard Floer homology groups of Y .K/ in terms of the knot Floer complex of .Y; K/. We strengthen this formula by adding a second filtration that computes the knot Floer complex of the dual knot K in Y , i.e., the core circle of the surgery solid torus. In the course of proving our refinement we derive a combinatorial formula for the Alexander grading which may be of independent interest.