double
has the range of ±5.0 × 10?324 to ±1.7 × 10308 and long
has the range of –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Unfortunately not all integral floating point values can be represented by an integer.
For example, 1e19
has already exceeded the range of a 64-bit signed integer.
(long)Math.Round(1e19) == -9223372036854775808L // WTF?
While it is true that the single-argument overloads Math.Round(double)
and Math.Round(decimal)
will always return an integral value, these overloads still cannot return an integer value type.
If you know that the value passed to the function will return a value representable by an integer value type, you can cast it yourself. The library won't do that because it needs to consider the general case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…