Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6229447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:34:05+00:00 2026-05-24T09:34:05+00:00

The code public class MyClass { public const Decimal CONSTANT = 0.50; // ERROR

  • 0

The code

public class MyClass
{
    public const Decimal CONSTANT = 0.50; // ERROR CS0664
}

produces this error:

error CS0664: Literal of type double cannot be implicitly converted to
type ‘decimal’; use an ‘M’ suffix to create a literal of this type

as documented. But this works:

public class MyClass
{
    public const Decimal CONSTANT = 50; // OK
}

Why did they forbid the first one? It seems weird to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:34:05+00:00Added an answer on May 24, 2026 at 9:34 am

    The type of a literal without the m suffix is double – it’s as simple as that. You can’t initialize a float that way either:

    float x = 10.0; // Fail
    

    The type of the literal should be made clear from the literal itself, and the type of variable it’s assigned to should be assignable to from the type of that literal. So your second example works because there’s an implicit conversion from int (the type of the literal) to decimal. There’s no implicit conversion from double to decimal (as it can lose information).

    Personally I’d have preferred it if there’d been no default or if the default had been decimal, but that’s a different matter…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn't valid code: public class MyClass { private static boolean yesNo = false;
Will this code cause a memory leak? #include <stdexept> class MyClass { public: MyClass()
I have read a parent Class called MyClass code like this, public class MyClass
With the code: template <typename T> class MyClass { public: MyClass(const MyClass& other) {
Look at the following code: class MyClass{ public: MyClass(){} MyClass(MyClass &&){} MyClass(const MyClass &){}
Consider the following code: public class MyClass { public static string MyStaticMethod() { //string
If I have the following code: public class MyClass { public string myName {
The following code works: @Stateless @LocalBean public class MyClass { @PersistenceContext(name = MyPU) EntityManager
I'm curious about the following code: class MyClass { public: MyClass() : _myArray(new int[1024])
class MyClass { public: void setVar(const char *str); private: std::string mStr; int maxLength; //we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.