

Since mLat is decimal (you said it is a spelling mistake) you try to get double * decimal which is clearly you get these error. The most common mnemonics for remembering this order of operations are: PEMDAS - Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. The calculator follows well-known rules for the order of operations.

Since Math.PI field represents double, your Math.PI / 180 will be double. This online decimals calculator will help you understand adding, subtracting, multiplying, or dividing decimals. Without the suffix m, the number is treated as a doubleĪnd there are no implicit conversions between floating-point types ( float and double) and the decimal type. If you want a numeric real literal to be treated as decimal, use the If you don't use any suffix with your floating type, C# thinks it is a double. If you want to use 12.123 as a decimal, you need to use m or M suffix.
#How do you do division with decimals code
Please see the below mentioned reference and what type is that you want to use in the present scenario that you are facing.įirst of all, your code doesn't even compile. MLon1 = mLon - mRadius / Math.Abs(Math.Cos(((Math.PI / 180D) * mLat)) * mFaktor) //mFaktor and mLon is not defined Here Convert.ToDouble(mLat) converts mLat to double since C# doesn't allow implicit conversion of decimal to double, why am I doing this? Well Math.Cos apparently accepts only double, so is the case of Math.AbsĪnother workaround is that you could convert every declared variables as double and reduce the pain of explicit type conversions in between double mLon1 = 0D ĭouble mFactor = 111021D //mFactor is never used MLon1 = mLon - mRadius / Math.Abs(Convert.ToDecimal(Math.Cos((Math.PI / 180) * Convert.ToDouble(mLat))) * mFaktor) //mFaktor and mLon is not defined C# is a type-safe language, what i meant by type safe is that the code allows the developer to be certain that a value or object will be of a certain type so that he/she can use it in a specific way without fear of unexpected or undefined behavior.Ĭ# only some implicit conversion of types like int to doubleĬhange your code as shown below decimal mLon1 = 0M ĭecimal mFactor = 111021M //mFactor is never used
