46

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

以下方法或属性之间的调用不明确:'System.Math.Round(double, int)' 和 'System.Math.Round(decimal, int)

我的代码是

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

我怎样才能解决这个问题?

谢谢

4

3 回答 3

52
Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
于 2009-04-21T09:38:37.510 回答
39

问题是您进行整数除法(也导致 an int)并且 aint可以隐式转换为doubleand decimal。因此,您需要确保表达式产生其中之一;double可能是你想要的。

Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
于 2009-04-21T09:38:08.307 回答
9
Math.Round((double) (new FileInfo(strFilePath).Length / 1024), 1)
于 2009-04-21T09:39:10.083 回答