Skip to content

Decimal.Multiply precision failing at decimal places between 4294.000000 and 4295.000000 for two decimal types multiplication #10222

@sachincholkar

Description

@sachincholkar

Type of issue

Code doesn't work

Description

//Code result = 0
decimal price = 0m;
decimal valUnits = 4295.000000m;
Console.WriteLine(Decimal.Multiply(price, valUnits));

//Code result = 0.000000
decimal price = 0m;
decimal valUnits = 4294.000000m;
Console.WriteLine(Decimal.Multiply(price, valUnits));

//Code result = 0.000000
decimal price = 0m;
decimal valUnits = 4295.00000m; //reduced decimal places to 5
Console.WriteLine(Decimal.Multiply(price, valUnits));

when working with decimal types, expectation is for result decimal to preserve the decimal zeros. Even if the result is 0, then it should be common for all the results.
Between 4294.000000 & 4295.000000, the binary values don't change significantly except for the lowest bit.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.decimal.multiply?view=net-8.0#system-decimal-multiply(system-decimal-system-decimal)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/Decimal.xml

Document Version Independent Id

4ec1f71e-31ee-e91a-5126-48b16ef44812

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.Runtimeneeds-author-actionAn issue or pull request that requires more info or actions from the author.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions