Returns the "correct" rounding DOWN of xy, assuming y>0. That is, the largest integer k such that k*y <= x. - CSharp System

CSharp examples for System:Math Number

Description

Returns the "correct" rounding DOWN of xy, assuming y>0. That is, the largest integer k such that k*y <= x.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  ww w.j  ava2  s  . c  o m*/

public class Main{
        /// <summary>
        /// Returns the "correct" rounding DOWN
        /// of x/y, assuming y>0.  That is, the largest
        /// integer k such that k*y <= x.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static int intDivide(float x, float y)
        {
            int r = (int)(x / y);

            return (r * y > x) ? r - 1 : r;
        }
        /// <summary>
        /// Returns the "correct" rounding DOWN
        /// of x/y, assuming y>0.  That is, the largest
        /// integer k such that k*y <= x.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static int intDivide(int x, int y)
        {
            int r = (int)(x / y);

            return (r * y > x) ? r - 1 : r;
        }
}

Related Tutorials