Let K be a rationally null-homologous knot in a 3-manifold Y, equipped with a non-zero 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.