0

I am confused at why its saying "literal of type cannot be implicity converted to type 'decimal'; use 'M' suffix. Unsure what use "'M'" is

        private void btnCalculate_Click(object sender, EventArgs e)
    {
        decimal decTotal = 0.00;
        decimal decTotalAfterDiscount;
        bool bolRadioChecked = false;

        if (chkHygienistTreatment.Checked == true) ;
        {
            decTotal = 119.50;
        }
        if (chkCheckupexam.Checked == true) ;
        {
            decTotal += 100;
        }
        if (chkCrecefilling.Checked == true) ;
        {
            decTotal += 126.30;
Baggins123
  • 11
  • 2

2 Answers2

0

you should change your code like this:

decimal decTotal = 0.00m;

because if you don't use the "m" the compiler doesn't understand that it should be treated as a decimal. that's how c# works.

Ehsan Kiani
  • 3,050
  • 1
  • 17
  • 19
0

In C#

0.00

Is a double literal. Which cannot be implicitly※ converted into decimal, because there are values representable in double that are not representable in decimal.

※: Implicitly meaning without an explicit cast (i.e. (decimal)0.00). Explicit cast may throw. Although a cast won't throw for this particular value.

You can add a "M" or "m" to the literal to make it a decimal literal instead:

0.00m

See also What does the M stand for in C# Decimal literal notation?.

Theraot
  • 31,890
  • 5
  • 57
  • 86