由于以下错误,我的代码无法编译:
以下方法或属性之间的调用不明确:'System.Math.Round(double,int)'和'System.Math.Round(decimal,int)
我的代码是
Math.Round(new FileInfo(strFilePath).Length / 1024, 1)
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
谢谢
Arc*_*rus 45
Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
Run Code Online (Sandbox Code Playgroud)
Luc*_*ero 29
问题是你进行整数除法(结果也在a中int),a int可以隐式转换为double和decimal.因此,您需要确保表达式导致其中一个; double可能就是你想要的.
Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
Run Code Online (Sandbox Code Playgroud)
Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)
Run Code Online (Sandbox Code Playgroud)