BigML.Utils.roundOff C# (CSharp) Method

roundOff() public static method

Round a double number x to n decimal places
public static roundOff ( double x, int n ) : double
x double
n int
return double
        public static double roundOff(double x, int n)
        {
            double bd = Math.Round((double)x, n, MidpointRounding.ToEven);
            return bd;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Prints distribution data
        /// </summary>
        public static StringBuilder printDistribution(JArray distribution)
        {
            StringBuilder distributionStr = new StringBuilder();

            int total = 0;

            foreach (object binInfo in distribution)
            {
                JArray binInfoArr = (JArray)binInfo;
                total += ((int)binInfoArr[1]);
            }

            foreach (object binInfo in distribution)
            {
                JArray binInfoArr = (JArray)binInfo;
                distributionStr.Append(string.Format("    {0}: {1:F2}% ({2:D} instance{3})\n", binInfoArr[0], Utils.roundOff((float)(((int)binInfoArr[1]) * 1.0 / total), 4) * 100, binInfoArr[1], (((int)binInfoArr[1]) == 1 ? "" : "s")));
            }


            return(distributionStr);
        }