
926 P.2d 781 (1996)
Ronald Dale KUYKENDALL, Appellant,
v.
The STATE of Nevada, Respondent.
No. 24796.
Supreme Court of Nevada.
November 7, 1996.
*782 Donald Green, Las Vegas, for Appellant.
Frankie Sue Del Papa, Attorney General, Carson City; Brian T. Kunzi, District Attorney, Mineral County, for Respondent.

OPINION
PER CURIAM:
Appellant Ronald Dale Kuykendall entered a plea of guilty to one count of manufacturing a controlled substance, NRS 453.321. Pursuant to former NRS 174.065(3), appellant was entitled to withdraw his plea if the district court sentenced appellant to more than the recommended maximum of ten years under the plea agreement. At the sentencing hearing on December 2, 1992, the district court stated that it disagreed with the handling of the case and with the recommended sentence. The district court stated that it was bound by the plea agreement, but would specifically refuse to grant credit for any of appellant's presentence confinement, and sentenced appellant to ten years in the Nevada State Prison. Subsequent to the entry of the judgment of conviction, appellant filed a motion to amend the judgment of conviction to allow credit for presentence jail time in the amount of 162 days. The district court summarily denied the motion by order filed July 7, 1993. This appeal followed.

DISCUSSION
Appellant contends that he was financially unable to post the bail set by the district court, and that the district court abused its discretion by denying him credit for the time served before sentencing. The parties do not dispute that appellant was held without bail from June 23, 1992, to September 12, 1992, a total of 81 days. After bail was set at $150,000, appellant did not post bail. Appellant remained confined from September 12, 1992, until sentencing on December 2, 1992, an additional 81 days.
NRS 176.055(1) provides, in pertinent part: "[W]henever a sentence of imprisonment in the county jail or state prison is imposed, the court may order that credit be allowed against the duration of the sentence...." This court has held that NRS 176.055
should also be construed to provide credit for confinement ... where (1) bail has been set for the defendant and (2) the defendant was financially unable to post the bail.... To provide otherwise would tolerate invidious discrimination based upon a defendant's financial status.
Anglin v. State, 90 Nev. 287, 292, 525 P.2d 34, 37 (1974).
As in Anglin, appellant's claim for the 81 days of presentence incarceration due to appellant's financial inability to post bail is based upon the Equal Protection Clause of the Fourteenth Amendment of the United States Constitution. See Tate v. Short, 401 U.S. 395, 398-99, 91 S.Ct. 668, 670-71, 28 L.Ed.2d 130 (1971), and Williams v. Illinois, 399 U.S. 235, 243-44, 90 S.Ct. 2018, 2023-24, 26 L.Ed.2d 586 (1970). We conclude that appellant is entitled to credit for the 81 days of presentence confinement resulting from appellant's financial inability to post bail, and the district court erred in denying appellant's motion for that amount of credit.
We further conclude that the district court erred in denying appellant's motion for credit for the remaining 81 days of presentence *783 confinement without bail. It is true that the language of NRS 176.055(1) and Anglin indicates that the award of credit for such presentence confinement is discretionary. Further, even in those states where credit for presentence incarceration is mandated by statute, some courts have specifically limited mandatory credit to presentence incarceration due to indigency. See, e.g., Milladge v. State, 900 P.2d 1156, 1160-61 (Wyo.1995). However, the California Supreme Court has reached the opposite conclusion, holding that the statute requiring mandatory credit applies to all felony convictions, not only to those in which presentence incarceration occurred as a result of indigency. In re Kapperman, 11 Cal.3d 542, 114 Cal.Rptr. 97, 101, 522 P.2d 657, 661 (1974). Under the California Supreme Court's analysis, the purpose of the statute is to ensure that all time served is credited towards a defendant's ultimate sentence. People v. Riolo, 33 Cal.3d 223, 188 Cal.Rptr. 371, 374, 655 P.2d 723, 726 (1983). The Massachusetts Court of Appeals has also concluded that mandatory credit under the applicable statute must be granted regardless of whether bail was set. Commonwealth v. Grant, 366 Mass. 272, 317 N.E.2d 484, 487 (1974). The First Circuit Court of Appeals upheld Grant, stating that "[t]here is nothing whatever irrational about a general rule that pretrial detention time should be credited as a matter of course...." Beauchamp v. Murphy, 37 F.3d 700, 707 (1st Cir.1994).
Despite the discretionary language of NRS 176.055(1), we agree with the reasoning of the California Supreme Court that the purpose of the statute is to ensure that all time served is credited towards a defendant's ultimate sentence. Accordingly, we conclude that the district court erred in denying appellant's motion for jail time credit for his 81 days of presentence confinement without bail.
For the foregoing reasons, we reverse the district court's order denying appellant's motion for jail time credit and remand this case to the district court with instructions to grant appellant jail time credit for 162 days of presentence confinement.
