Using MOD in C# RRS feed

  • Question

  • Hi,

    I am converting Excel formula from Excel to C# but could not figure out the MOD and how to get it in C#

    My formula is like this:

    MOD(Math.atan2((Math.Cos(latt_from_radians)*Math.Sin(latt_to_radians))-(Math.Sin(latt_from_radians)*Math.Cos(latt_to_radians)*Math.Cos(lang_to_radians-long_from_radians)), Math.SIN(lang_to_radians-long_from_radians)*Math.Cos(latt_to_radians)),2*Math.PI)



    Saturday, August 17, 2019 11:55 PM

All replies

  • It is % : Decimal.Modulus(Decimal, Decimal) Operator

    (and ATAN2 parameters are inverted from my test...)

    Sunday, August 18, 2019 7:43 AM
  • Hi Jassim Rahma, 

    Thank you for posting here.

    As Castorix31 suggested, you can use ‘%’ to convert the formula.

    Here’s the code:

                double d = Math.Atan2(Math.Sin(lang_to_radians - long_from_radians) * Math.Cos(latt_to_radians),
                    (Math.Cos(latt_from_radians) * Math.Sin(latt_to_radians)) -
                    (Math.Sin(latt_from_radians) * Math.Cos(latt_to_radians) * Math.Cos(lang_to_radians - long_from_radians)))
                    % (2 * Math.PI);

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, August 23, 2019 8:56 AM