0

As described above I have some Theories to test about receiving a decimal(18,2) parameter. Which means that, supposedly, should accept a 16 integers on the left side and two integers decimals, with the highets number possible as 9999999999999999.99.

[Theory]
[InlineData(999.99)]
[InlineData(9999999999999999.99)] 
[InlineData(0000000000000000.01)]
public void A_Cool_Test_Case(decimal decimalCoolValues)
{
     //...

But, xUnit is rouding this value to 10000000000000000. Is this normal behaviour or am I missing something here?

J...
  • 30,968
  • 6
  • 66
  • 143
  • Please edit your question to provide the code as *text* rather than an image. The code is inherently text - it's better in every possible way to have it as text in your question. (For one thing, I'd probably have copy/pasted and edited it into my answer if you'd done so - but I'm not about to retype the whole thing.) – Jon Skeet Dec 07 '21 at 17:59

1 Answers1

3

No, xUnit isn't rounding it. The compiler is, because you have unreasonable expectations of what can be stored in a double value.

From the docs:

A Double value has up to 15 decimal digits of precision, although a maximum of 17 digits is maintained internally.

So trying to store 18 digits is really asking for trouble.

Your literals are double literals, but you have a decimal parameter. It's unfortunate that you can't specify a decimal literal in an attribute, but in this case I'd suggest specifying the value as a string literal. It's possible that xUnit will parse that for you and you can keep the decimal parameter... otherwise, change it to a string parameter and parse the value yourself in your test.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thank you Jon! I got the problem as it's the direct conversion for Double in InlineData as a parameter, so your answer along that other question suggestion did the trick! Really Thanks for your help! :) – Pedro Henrique Rissato Dec 07 '21 at 18:46