0

Using FluentAssertions, is there any nice way to confirm the number of characters after a decimal point? I've been looking for the best way to do this but can't find much on it.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • There's nothing built-in for this, but it seems like the first thing you'll need to do is [count the number of decimal digits in the number](https://stackoverflow.com/questions/13477689/find-number-of-decimal-places-in-decimal-value-regardless-of-culture). – gunr2171 Sep 14 '21 at 19:07
  • `var digits = numberString.Length - numberString.LastIndexOf(CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator) - 1;` – John Wu Sep 15 '21 at 06:16

2 Answers2

0

Or use Should().MatchRegex() on the string representation.

Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44
-1

I believe you should use Should().BeApproximately(args) or Should.BeInRange(args)

Rafal Kozlowski
  • 224
  • 2
  • 2