예제 #1
0
        /// <summary>
        /// Creates the DecimalFormat used to write doubles with a sufficient
        /// number of decimal places.
        /// </summary>
        /// <param name="precisionModel">
        /// The PrecisionModel used to determine the number of decimal places to
        /// write.
        /// </param>
        /// <returns>
        /// A DecimalFormat that write double without scientific notation.
        /// </returns>
        internal virtual TextNumberFormat CreateFormatter(PrecisionModel precisionModel)
        {
            if (m_objUserPrecision != null)
            {
                precisionModel = m_objUserPrecision;
            }

            // the default number of decimal places is 16, which is sufficient
            // to accomodate the maximum precision of a double.
            int decimalPlaces = precisionModel.MaximumSignificantDigits;
            // specify decimal separator explicitly to avoid problems in other locales

            NumberFormatInfo symbols = null;

            if (m_objCulture != null)
            {
                symbols = m_objCulture.NumberFormat;
            }

            if (symbols == null)
            {
                symbols = new NumberFormatInfo();
                if (decimalPlaces > 0)
                {
                    symbols.NumberDecimalSeparator = '.'.ToString();
                }
            }

            m_objProvider = symbols;

            TextNumberFormat numberFormatter = TextNumberFormat.GetTextNumberInstance(symbols);

            numberFormatter.MaxFractionDigits = decimalPlaces;
            numberFormatter.DirectFormat      = true;

            return(numberFormatter);
        }