Skip to content

add method to directly round double to decimal #21670

@coderb

Description

@coderb

the current version of the API requires 2 rounding operations to convert from a double to a decimal with n places of precision.

eg

double d = ...;
decimal m1 = (decimal)d; // first rounding operation
decimal m2 = Math.Round(m1, n, MidpointRounding.AwayFromZero); // second rounding operation

ideally we would have an API that allows a direct conversion/round in a single operation:

in class Decimal:

public static decimal Round(double d, int n, MidpointRounding rouding) {}

this is both for performance and correctness reasons. rounding twice may introduce inaccuracies (albeit subtle and infrequent) and also inccurs an extra unnecessary step.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workAPI needs work before it is approved, it is NOT ready for implementationarea-System.Numerics

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions