代码之家  ›  专栏  ›  技术社区  ›  Lalit

是否将float.maxValue强制转换为long throws异常?

  •  3
  • Lalit  · 技术社区  · 14 年前

    试图获取float.maxvalue的整数部分,但它引发了错误?

            long l = Convert.ToInt64(float.MaxValue);
            Console.WriteLine(l);
    

    错误: 算术运算导致溢出。

    5 回复  |  直到 14 年前
        1
  •  6
  •   Community CDub    7 年前

    float long float.MaxValue

    Convert.ToInt64 OverflowException Int64.MaxValue Int64.MinValue

    this question

        2
  •  6
  •   Ani    14 年前

    float long What Every Computer Scientist Should Know About Floating-Point Arithmetic

    float.MaxValue ~= 3.402823+e38
    long.MaxValue ~= 9.223372+e18
    

    float.MaxValue

    System.Numerics.BigInteger appropriate constructor

    format-specifier

    //output: "340282300000000000000000000000000000000"
    Console.WriteLine(float.MaxValue.ToString("F0"));
    
        3
  •  3
  •   Keith    14 年前
        4
  •  0
  •   arena-ru    14 年前
        5
  •  0
  •   Phil Helix    14 年前