Error Name:
The call is ambiguous between the following methods or properties: 'System.Math.Floor(decimal)' and 'System.Math.Floor(double)'....
This is my program line:
The above error shows here in my program. i dono how to correct this error...
short nHalf = (short)Math.Floor(nDegree/2);
AlanPosted Aug 25, 2007, 6:05 AM
The Math.Floor method has two overrides - one that takes a double argument and one that takes a decimal.
I would imagine that the variable nDegree is some kind of integer and therefore so too is nDegree/2. Consequently, the compiler doesn't know which override to use.
However, unless nDegree can be negative, you don't actually need to use Math.Floor here.If nDegree is even, then nDegree/2 will be exactly one half of it and, if nDegree is odd (45 say), then nDegree/2 will be automatically rounded down to the lower integer (i.e. 22).
So you could just use:
short nHalf = (short)(nDegree/2);
However, if nDegree could be negative, you could use:
short nHalf = (short)Math.Floor((double)nDegree/2.0);
The cast and use of a double literal (i.e. 2.0) forces the compiler to use floating point arithmetic instead of integer arithmetic.