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

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...