【问题标题】:FluentAssertions to check number of characters after decimal pointFluentAssertions 检查小数点后的字符数
【发布时间】:2021-11-09 23:07:13
【问题描述】:

使用FluentAssertions,有什么好的方法可以确认小数点后的字符数吗?我一直在寻找最好的方法来做到这一点,但找不到太多。

【问题讨论】:

  • 没有任何内置功能,但您需要做的第一件事似乎是count the number of decimal digits in the number
  • var digits = numberString.Length - numberString.LastIndexOf(CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator) - 1;

标签: c# .net fluent-assertions


【解决方案1】:

或者在字符串表示上使用Should().MatchRegex()

【讨论】:

    【解决方案2】:

    我相信你应该使用Should().BeApproximately(args)Should.BeInRange(args)

    【讨论】:

    • 值和精度是不同的东西。
    • 啊,你完全正确。我不知道为什么我会这样想。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 2016-01-12
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 2015-01-06
    • 2012-08-12
    相关资源
    最近更新 更多