gpt4 book ai didi

c# - 配置流利的断言精度以比较小数

转载 作者:行者123 更新时间:2023-12-05 03:00:00 26 4
gpt4 key购买 nike

我正在使用 fluent-assertions 和存储严重小数类型的 sqlite 编写单元测试。

我希望ALL 我的十进制比较忽略 float 部分。

有办法吗?

谢谢!

最佳答案

FluentAssertions 允许对十进制/ float 值进行近似断言。

The following method is specifically designed for floating point or decimal variables.

float value = 3.1415927F;
value.Should().BeApproximately(3.14F, 0.01F);

This will verify that the value of the float is between 3.139 and 3.141.

引用FluentAssertions Documentation: Numeric types and everything else that implements IComparable<T>

关于c# - 配置流利的断言精度以比较小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57384306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com