System.Xml.Xsl.Runtime.XsltFunctions.Round C# (CSharp) Method

Round() public static method

public static Round ( double value ) : double
value double
return double
        public static double Round(double value)
        {
            double temp = Math.Round(value);
            return (value - temp == 0.5) ? temp + 1 : temp;
        }

Usage Example

        private void FormatItem(StringBuilder sb, XPathItem item, char startChar, int length)
        {
            double dblVal;

            if (item.ValueType == typeof(int))
            {
                dblVal = (double)item.ValueAsInt;
            }
            else
            {
                Debug.Assert(item.ValueType == typeof(double), "Item must be either of type int, or double");
                dblVal = XsltFunctions.Round(item.ValueAsDouble);
            }

            Debug.Assert(1 <= dblVal && dblVal < double.PositiveInfinity);
            char zero = '0';

            switch (startChar)
            {
            case '1':
                break;

            case 'A':
            case 'a':
                if (dblVal <= MaxAlphabeticValue)
                {
                    ConvertToAlphabetic(sb, dblVal, startChar, 26);
                    return;
                }
                break;

            case 'I':
            case 'i':
                if (dblVal <= MaxRomanValue)
                {
                    ConvertToRoman(sb, dblVal, /*upperCase:*/ startChar == 'I');
                    return;
                }
                break;

            default:
                Debug.Assert(CharUtil.IsDecimalDigitOne(startChar), "Unexpected startChar: " + startChar);
                zero = (char)(startChar - 1);
                break;
            }

            sb.Append(ConvertToDecimal(dblVal, length, zero, _groupingSeparator, _groupingSize));
        }