
828 P.2d 392 (1992)
Arlin HOVELAND, Wendy Hoveland, individually and as guardian for Danyel Hoveland, Plaintiffs and Appellants,
v.
Charles E. PETAJA, Defendant and Respondent.
No. 91-032.
Supreme Court of Montana.
Submitted on Briefs December 4, 1991.
Decided March 24, 1992.
Ronald F. Waterman, Gough, Shanahan, Johnson & Waterman, Helena, for plaintiffs and appellants.
Charles E. Petaja, pro se.
HUNT, Justice.
Appellants Arlin and Wendy Hoveland and their minor child, Danyel, appeal from an order of the First Judicial District Court, Lewis and Clark County, converting a motion to dismiss into a motion for summary judgment without giving notice to the parties and granting the motion for summary judgment in favor of the respondent, Charles E. Petaja.
We reverse and remand.
Appellants raise the following issues for this Court to consider:
1. Whether the District Court erred in converting a motion to dismiss into a motion for summary judgment without giving notice to the appellants, thereby denying them a reasonable opportunity to present all material pertinent to Rule 56, M.R.Civ.P.
2. Whether the District Court erred when it granted summary judgment to the defendant.
On September 6, 1987, appellants and daughter were injured in an automobile accident near Townsend. Appellants filed a lawsuit against John Dinsmore and the State of Montana, alleging negligence.
Prior to the filing of the lawsuit, appellants retained respondent as counsel. On September 29, 1987, appellants signed a contingency fee agreement with the respondent. This agreement allowed respondent to recover 30 percent of any settlement obtained. It also provided that appellants pay for costs and expenses of the litigation. The lawsuit continued to progress for three years. During that period, respondent had advanced moneys for costs of litigation and other expenses that appellant incurred.
On October 12, 1989, appellant Arlin Hoveland and respondent entered into another contingency fee agreement. The second agreement allowed respondent to receive 40 percent of any settlement obtained. Neither Mrs. Hoveland nor Danyel signed the second agreement.
On January 8, 1990, the lawsuit with Dinsmore was settled, and the State settled a few weeks later. The total amount of the settlement was approximately $260,000.
On January 18, 1990, respondent went to appellants' home and presented the family with an accounting of $141,978.81 based on the 30 percent contingency agreement. *393 This amount only included the Dinsmore settlement because the State had not yet settled. The appellants disputed the amount. They allege that as an inducement to settle, respondent represented to them that he would reduce his fee and pay expenses and costs of the litigation, guaranteeing the appellants $175,000. Appellants rejected the accounting. Respondent did not tender any money due to the appellants, and deposited $141,978.81 into an account exclusively under his control. Appellants allege that some of this money has been spent on purposes other than the trust provided to appellants. Pursuant to a motion, the account was frozen by the District Court on April 23, 1990. On August 23, 1990, the court released the funds in the account to the appellants. The amount totaled approximately $100,000.
On May 23, 1990, appellants filed a complaint against respondent on the basis of fraud, negligence, and contract theories. On July 30, 1990, respondent filed a motion to dismiss, a motion to strike, and a motion for a more definite statement. Respondent alleged that pursuant to the 40 percent contingency agreement, appellants were entitled to only $115,000. Both sides filed the appropriate briefs and attached exhibits. In addition, both parties filed notices of submittal and waived oral argument.
On November 21, 1990, the District Court issued its ruling. The court converted the motion to dismiss into a motion for summary judgment. The court failed to give notice of its intention to convert the motions, and granted the motion for summary judgment in favor of the respondent. On November 29, 1990, appellants filed a motion for relief from judgment. The court denied the motion. Appellants appeal.

I
The first issue to be resolved is whether the District Court erred in converting a motion to dismiss into a motion for summary judgment without giving notice to the appellants, thereby denying them a reasonable opportunity to present all material pertinent to Rule, 56 M.R.Civ.P.
A motion to dismiss under Rule 12(b)(6), M.R.Civ.P., allows the District Court to only examine whether "a claim has been adequately stated in the complaint." Gebhardt v. D.A. Davidson & Co. (1983), 203 Mont. 384, 389, 661 P.2d 855, 857. The District Court may only inquire into the content of the complaint. Gebhardt, 661 P.2d at 857. The effect of such a motion is admitting to all the well pleaded allegations in the complaint and it should not be dismissed "unless it appears beyond a reasonable doubt that the plaintiff can prove no set of facts which would entitle him to relief." Gebhardt, 661 P.2d at 858.
However, Rule 12(b), M.R.Civ.P., allows the court to convert a motion to dismiss into a motion for summary judgment when matters outside the pleadings are presented to the court. Rule 12(b), M.R.Civ.P., states in part:
If, on a motion asserting the defense numbered (6) to dismiss for failure of the pleading to state a claim upon which relief can be granted, matters outside the pleading are presented to and not excluded by the court, the motion shall be treated as one for summary judgment and disposed of as provided in Rule 56, and all parties shall be given reasonable opportunity to present all material made pertinent to such motion by Rule 56.
Thus, the court may use its discretion to exclude matters outside of the pleadings when considering a motion to dismiss. If it decides to include such matters outside of the pleadings, then it shall treat the motion as a motion for summary judgment.
Previously we have held that before a court can convert a motion to dismiss into a motion for summary judgment, it must give notice to the parties of its intention to convert the motion. State ex rel. Dept. of Health and Environmental Sciences v. City of Livingston (1976), 169 Mont 431, 436, 548 P.2d 155, 157; Graveley v. MacLeod (1978), 175 Mont. 338, 344, 573 P.2d 1166, 1169. The purpose of notice is to *394 allow the parties a reasonable opportunity to present all material made pertinent to the motion and avoid surprise.
Formal notice by the court gives the party opposing the motion for summary judgment an opportunity to produce additional facts by affidavit or otherwise which would create a genuine issue of material fact to preclude summary judgment under Rule 56, M.R.Civ.P. First Federal Savings and Loan v. Anderson (1989), 238 Mont. 296, 299, 777 P.2d 1281, 1283.
We hold that the District court erred in failing to give notice of its intention to convert a motion to dismiss into a motion for summary judgment.
As a result of our holding in Issue I above, we need not discuss Issue II.
Reversed and remanded.
TURNAGE C.J., and TRIEWEILER, McDONOUGH and WEBER, JJ., concur.
