9

I am using Mvc framework and i want to migrate vb code to c#. Right now i want to use** FIX ** function equivalent in c#

Example:- Vb Code

result.ReducedDegrees= Fix(dblReducedAngle)    
result.ReducedMinutes = Fix((dblReducedAngle - Fix(dblReducedAngle)) * 60)

I want to get result in c#

3
  • 2
    Have a look at this. You're looking for Math.Floor / Math.Ceiling. Mar 30, 2016 at 6:46
  • 1
    Math.Ceiling is working for me ,Thanks @diiN_
    – Naveen
    Mar 30, 2016 at 6:54
  • Math.Ceiling only works for positive numbers, mind. Use Math.Truncate to make it work for both positive and negative numbers.
    – Wazner
    Mar 30, 2016 at 6:55

1 Answer 1

10

The Fix function removes the fractional part of a numeric expression. Closely the same functionality as Int, except the Fix method has a special clause at the bottom:

If Number is negative, Fix returns the first negative integer greater than or equal to Number.

In C#, there is the Math.Truncate method which you can use. It has the same properties as VB's Fix method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.