Skip to content

Numeric comparison fails when it should succeed. #3999

@manfred-brands

Description

@manfred-brands

@stevenaw This fails on 3.13-dev, but succeeds on 3.13.2, it was introduced with #3898

[Test]
public void Decimal()
{
    const double value = 1.0000000000000038d;

    Assert.Multiple(() =>
    {
        Assert.That(value > 1.0, Is.True, "> 1.0");
        Assert.That(value, Is.GreaterThan(1.0), "Is.GreaterThan(1.0)");
    });
}

This fails with:

Message: 
  Is.GreaterThan(1.0)
  Expected: greater than 1.0d
  But was:  1.0000000000000038d

The error is in the conversion to decimal. Despite the type claiming to have 28 digits of precision,
Convert.ToDecimal(value) results in 1 dropping all fractional digits.

Even though the comparison uses decimal the error message uses the original values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions