用数字保证精度?

Guaranteed precision with numerics?

我了解到由于浮点数的存储方式,有些值无法准确表示。 (参见 Why Are Floating Point Numbers Inaccurate?

也就是说,在 .NET / C# 中,在精度方面有哪些选择或保证? https://msdn.microsoft.com/en-us/library/b1e65aza.aspx?f=255&MSPPError=-2147217396 指的是 "approximate" 范围。为什么在这种情况下需要近似值?

最终,我希望存储如下值:

x.xxxxxxxx

其中值始终为正。这似乎不是一个非常精确的数字,但我想确定上面所有可能的数字组合都是 "durable."

编辑:

为了阐明我想要的确切精度级别,我希望小数点后有八位数字,小数点左边有一位数字。

听起来您正在寻找 decimal

来自link:

Precision 28-29 significant digits

Approximate Range (pasting doesn't give the formatting of the exponent etc. so just check out the link.)

what options or guarantees does one have in terms of precision

根据文档,维基百科浮点数的精度为 7 位有效小数位精度

类似于 1234567 或 1.234567 或 0.0000001234567

Why is an approximation necessary in this context

因为不准确。 IEEE 754 浮点值是 (2 − 2−23) × 2127 ≈ 3.402823 × 10^38

虽然你可能会得到一个像 3.4028239999 × 10^38 这样的数字,但最后 5 位数字 (99999) 不可信