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.
Asked
Active
Viewed 226 times
0

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 Answers
-1
I believe you should use Should().BeApproximately(args)
or Should.BeInRange(args)

Rafal Kozlowski
- 224
- 2
- 2
-
-
Ah, you're completely right. I have no idea why I thought about this that way. – Rafal Kozlowski Sep 16 '21 at 07:14