Skip to content

Precision error when calculating small volumes #1199

Closed
@mortenbock

Description

@mortenbock

Describe the bug
Given this unit test:

[Test]
public void Foo()
{
    Length length = Length.FromMillimeters(10);
    Length width = Length.FromMillimeters(10);
    Length height = Length.FromMillimeters(10);

    Volume volume = length * width * height;

    Assert.That(volume.CubicMillimeters, Is.EqualTo(1000));
}

The test fails with:

Expected: 1000
But was:  1000.0000000000001d

It seems that working with small units means that the precision of the calculations are not correct?

Using version 5.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions