2 Samuel 24:21

And Araunah said, Wherefore is my lord the king come to his servant? And David said, To buy the threshingfloor of thee, to build an altar unto the LORD, that the plague may be stayed from the people.

David went to Araunah to purchase his threshingfloor in order to build an altar unto the LORD and make atonement for his sin in numbering Israel, so that the plague might be stayed from the people. He acted under God's direction given through His prophet to make that atonement for his sin. The plague was then destroying seventy thousand people. Araunah offered the threshingfloor freely, together with cattle and everything needful for sacrifice, but David refused to take it as a free gift and insisted on buying it for full price.

Though the LORD accepts the sacrifice the sinner is willing to make, David would not come before the LORD with an offering that cost him nothing. His heart was in the work, and so his repentance was accepted. There he offered burnt offerings and peace offerings. God accepted the offerings by sending fire from heaven to consume the sacrifice, and by commanding the angel to put his sword into its sheath and cease death and destruction at Jerusalem.