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 6089577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:06:55+00:00 2026-05-23T12:06:55+00:00

If we declare padding as const decimal, the padding is not working. mymoney =

  • 0

If we declare padding as const decimal, the padding is not working.

mymoney = 1.2 and your money = 1.20, how can this behavior be explained?

class Program
{
    static void Main(string[] args)
    {
        decimal balance = 1.2m;

        const decimal ConstPadding = 0.00m;

        decimal padding = 0.00m;
        decimal mymoney = decimal.Round(balance + ConstPadding, 2);
        decimal yourmoney =  decimal.Round(balance + padding, 2);

        Console.WriteLine(mymoney); // 1.2
        Console.WriteLine(yourmoney);  //1.20
    }
}
  • 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-23T12:06:56+00:00Added an answer on May 23, 2026 at 12:06 pm

    As an accompaniment to Jon’s answer, below is the IL produced from your code. As he mentioned, mymoney was never added.

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       61 (0x3d)
      .maxstack  6
      .locals init ([0] valuetype [mscorlib]System.Decimal balance,
               [1] valuetype [mscorlib]System.Decimal padding,
               [2] valuetype [mscorlib]System.Decimal mymoney,
               [3] valuetype [mscorlib]System.Decimal yourmoney)
      IL_0000:  nop
      IL_0001:  ldc.i4.s   12
      IL_0003:  ldc.i4.0
      IL_0004:  ldc.i4.0
      IL_0005:  ldc.i4.0
      IL_0006:  ldc.i4.1
      IL_0007:  newobj     instance void [mscorlib]System.Decimal::.ctor(int32,
                                                                         int32,
                                                                         int32,
                                                                         bool,
                                                                         uint8)
      IL_000c:  stloc.0
      IL_000d:  ldc.i4.0
      IL_000e:  ldc.i4.0
      IL_000f:  ldc.i4.0
      IL_0010:  ldc.i4.0
      IL_0011:  ldc.i4.2
      IL_0012:  newobj     instance void [mscorlib]System.Decimal::.ctor(int32,
                                                                         int32,
                                                                         int32,
                                                                         bool,
                                                                         uint8)
      IL_0017:  stloc.1
      IL_0018:  ldloc.0
      IL_0019:  ldc.i4.2
      IL_001a:  call       valuetype [mscorlib]System.Decimal [mscorlib]System.Decimal::Round(valuetype [mscorlib]System.Decimal,
                                                                                              int32)
      IL_001f:  stloc.2
      IL_0020:  ldloc.0
      IL_0021:  ldloc.1
      IL_0022:  call       valuetype [mscorlib]System.Decimal [mscorlib]System.Decimal::op_Addition(valuetype [mscorlib]System.Decimal,
                                                                                                    valuetype [mscorlib]System.Decimal)
      IL_0027:  ldc.i4.2
      IL_0028:  call       valuetype [mscorlib]System.Decimal [mscorlib]System.Decimal::Round(valuetype [mscorlib]System.Decimal,
                                                                                              int32)
      IL_002d:  stloc.3
      IL_002e:  ldloc.2
      IL_002f:  call       void [mscorlib]System.Console::WriteLine(valuetype [mscorlib]System.Decimal)
      IL_0034:  nop
      IL_0035:  ldloc.3
      IL_0036:  call       void [mscorlib]System.Console::WriteLine(valuetype [mscorlib]System.Decimal)
      IL_003b:  nop
      IL_003c:  ret
    } // end of method Program::Main
    

    To produce the IL (i.e. if you want to look under the hood in the future), just run ILDASM from a VS command prompt, then load your executable and double-click on the method that you would like to look at.

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

Sidebar

Related Questions

Declare @BadDecimal varchar(5) Set @BadDecimal = '4.5' Declare @GoodDecimal Decimal Set @GoodDecimal = @BadDecimal
In Oracle I can declare a reference cursor... TYPE t_spool IS REF CURSOR RETURN
Is there anyway to declare an object of a class before the class is
I declare a variable for a 64 bit counter as : long long call_count;
I declare a static char array, then I pass it to a function. How
Why does Visual Studio declare new classes as private in C#? I almost always
If you declare variables of type byte or short and attempt to perform arithmetic
Given the following: declare @a table ( pkid int, value int ) declare @b
When you attempt to declare an unsigned variable in C#.NET with a value outside
If I declare a temporary auto deleted character buffer using std::auto_ptr<char> buffer(new char[n]); then

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.