tags:

views:

2502

answers:

3

My code won't compile due to the error below:

The call is ambiguous between the following methods or properties: 'System.Math.Round(double, int)' and 'System.Math.Round(decimal, int)

My code is

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

How can I fix this?

Thanks

+1  A: 

The problem is that you make an integer division (results also in an int) and a int can be implicitly converted to both double and decimal. Therefore, you need to make sure the expression results in one of those; double is probably whal you want.

Math.Round(new FileInfo(strFilePath).Length / 1024.0, 1)
Lucero
+4  A: 
Math.Round(new FileInfo(strFilePath).Length / 1024d, 1)
Arcturus
This is way better than the accepted answer, you should not implicitly cast using ".0", using 'd' suffix is explicit and preferred.
A: 

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

edosoft