C# Error CS0664 – Literal of type double cannot be implicitly converted to type ‘{1}’; use an ‘{0}’ suffix to create a literal of this type

C# Error

CS0664 – Literal of type double cannot be implicitly converted to type ‘{1}’; use an ‘{0}’ suffix to create a literal of this type

Reason for the Error & Solution

Literal of type double cannot be implicitly converted to type ‘type’; use an ‘suffix’ suffix to create a literal of this type

An assignment could not be completed; use a suffix to correct the instruction. The documentation for each type identifies the corresponding suffix for the type. For more information on conversions, see .

The following sample generates CS0664:

// CS0664.cs  
class Example  
{  
    static void Main()  
    {  
        decimal d1 = 1.0;   // CS0664, because 1.0 is interpreted  
                            // as a double.  
  
        // Try the following line instead.  
        decimal d2 = 1.0M;  // The M tells the compiler that 1.0 is a  
                            // decimal.  
        Console.WriteLine(d2);  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...