Почему находится арифметика с плавающей точкой в неточном C#?

получение меток способа оплаты

foreach ($array as $value) 
{
 $all_labels=$value['label'];
}
13
задан Mark Lakata 28 December 2015 в 00:13
поделиться

2 ответа

Floating point only has so many digits of precision. If you're seeing f1 == f2, it is because any difference requires more precision than a 32-bit float can represent.

I recommend reading What Every Computer Scientist Should Read About Floating Point

37
ответ дан 1 December 2019 в 17:51
поделиться

The main thing is that this isn't just .Net: it's a limitation of the underlying system most every language will use to represent a float in memory. The precision only goes so far.

You can also have some fun with relatively simple numbers, when you take into account that it's not even base ten. 0.1, for example, is a repeating decimal when represented in binary.

5
ответ дан 1 December 2019 в 17:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: