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

C以下方法或属性之间的调用不明确:“system.math.round(double,int)”和“system.math.round(decimal,int)”。

  •  34
  • James  · 技术社区  · 17 年前

    由于以下错误,我的代码无法编译:

    以下方法或属性之间的调用不明确:“System.Math.Round(Double,int)”和“System.Math.Round(Decimal,int)”。

    我的代码是

    Math.Round(new FileInfo(strFilePath).Length / 1024, 1)
    

    我怎么修这个?

    谢谢

    3 回复  |  直到 9 年前
        1
  •  25
  •   BornToCode    9 年前

    问题是你做了一个整数除法(也得到了 int 和A int 可以隐式转换为 double decimal . 因此,您需要确保表达式产生其中一个结果; 双重的 可能是你想要的。

    Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
    
        2
  •  43
  •   Arcturus    17 年前
    Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
    
        3
  •  4
  •   Zain Rizvi viperguynaz    11 年前
    Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)