Decimal Multiplication and Division

I am new to C # and now have a problem with math stuff. Why can't I split or split “just” like this:

 decimal mLon1 = 0;
 decimal mLat1 = 0;
 decimal mFactor = 111021;
 decimal mRadius = 100;
 decimal mLat = 12.123;

 mLon1 = mLon - mRadius / Math.Abs(Math.Cos(((Math.PI / 180) * mLat)) * mFaktor);
 mLat1 = mLat - (mRadius / mFaktor);

Compiler Show error:

The '*' operator cannot be applied to operands of type double and decimal.

Same thing with the '/' operator ...

How can I make my code work? thanks for any hint.

+4
source share
5 answers

try under the code and you have a spelling error next to "mFaktor", which should be "mFactor"

decimal mLon1 = 0;
decimal mLat1 = 0;
decimal mFactor = 111021;
decimal mRadius = 100;
decimal mLat = (decimal)12.123;
decimal mLon = 0;
mLon1 = mLon - mRadius / (decimal)Math.Abs(Math.Cos(((Math.PI / 180) * (double)mLat)) * (double)mFactor);
mLat1 = mLat - (mRadius / mFactor);
0
source

# - , , , , , , / , undefined . # , int,

,

decimal mLon1 = 0M;
decimal mLat1 = 0M;
decimal mFactor = 111021M;//mFactor is never used
decimal mRadius = 100M;
decimal mLat = 12.123M;

mLon1 = mLon - mRadius / Math.Abs(Convert.ToDecimal(Math.Cos((Math.PI / 180) * Convert.ToDouble(mLat))) * mFaktor);//mFaktor and mLon is not defined
mLat1 = mLat - (mRadius / mFaktor);

Convert.ToDouble(mLat) mLat double, # decimal double, ? Math.Cos, -, double, Math.Abs

, double

double mLon1 = 0D;
double mLat1 = 0D;
double mFactor = 111021D;//mFactor is never used
double mRadius = 100D;
double mLat = 12.123D;

mLon1 = mLon - mRadius / Math.Abs(Math.Cos(((Math.PI / 180D) * mLat)) * mFaktor);//mFaktor and mLon is not defined
mLat1 = mLat - (mRadius / mFaktor);

. .

Floating point reference

: MSDN

+3

. , .

(64 ), - , 128 .

, .

+2

, .

12.123 decimal, m m. , # , double.

decimal ( #)

, , m M. m .

(float double) decimal.

Math.PI double, Math.PI / 180 double. mLat decimal ( , ), double * decimal, , , . /.

# Spec $7.7.1

float operator *(float x, float y);
double operator *(double x, double y);
decimal operator *(decimal x, decimal y);

# Spec $7.7.2

float operator /(float x, float y);
double operator /(double x, double y);
decimal operator /(decimal x, decimal y);

, double * decimal double / decimal.

+1

double decimal.

0

Source: https://habr.com/ru/post/1533672/


All Articles