Convert with a bad float in C # using VS2012

I get very strange behavior here with C #:

float num = 144771463f;
// num is 144771456.0

I also tried

float num = Convert.ToSingle(144771463f);
// num is still 144771456.0

Why is this happening?

+4
source share
1 answer

In a type, System.Singleyou lose the inherent restrictions ( float- this is an alias of the name Single).

According to MSDN ( http://msdn.microsoft.com/en-us/library/system.single.aspx ) the type Singlehas 22 bits intended for the mantissa (also known as value) these are bits that store the actual "digits" in value (the remaining 10 bits retain the positive / negative sign and exponent).

22 , 0 - 4,194,304, , , 144,771,463, 2 () 7- Single. , 144,771,46X ( X , ).

:

  • System.Double, 51
  • System.Decimal, 96 , , Decimal , ( , ).
+7

Source: https://habr.com/ru/post/1539154/


All Articles