System.Xml.Xsl.Runtime.DecimalFormatter.Format C# (CSharp) Method

Format() public method

public Format ( double value ) : string
value double
return string
        public string Format(double value) {
            NumberFormatInfo formatInfo;
            string subPicture;

            if (value < 0 && negFormatInfo != null) {
                formatInfo = this.negFormatInfo;
                subPicture = this.negFormat;
            } else {
                formatInfo = this.posFormatInfo;
                subPicture = this.posFormat;
            }

            string result = value.ToString(subPicture, formatInfo);

            if (this.zeroDigit != '0') {
                StringBuilder builder = new StringBuilder(result.Length);
                int shift = this.zeroDigit - '0';
                for (int i = 0; i < result.Length; i++) {
                    char ch = result[i];
                    if ((uint)(ch - '0') <= 9) {
                        ch += (char)shift;
                    } else if (ch == EscChar) {
                        // This is an escaped literal digit or EscChar, thus unescape it. We make use
                        // of the fact that no extra EscChar could be inserted by value.ToString().
                        Debug.Assert(i+1 < result.Length);
                        ch = result[++i];
                        Debug.Assert('0' <= ch && ch <= '9' || ch == EscChar);
                    }
                    builder.Append(ch);
                }
                result = builder.ToString();
            }
            return result;
        }

Same methods

DecimalFormatter::Format ( double value, string formatPicture, DecimalFormat decimalFormat ) : string

Usage Example

Ejemplo n.º 1
0
        public string FormatNumberDynamic(double value, string formatPicture, XmlQualifiedName decimalFormatName, string errorMessageName)
        {
            DecimalFormat?format;

            if (_decimalFormats == null || !_decimalFormats.TryGetValue(decimalFormatName, out format))
            {
                throw new XslTransformException(SR.Xslt_NoDecimalFormat, errorMessageName);
            }

            DecimalFormatter formatter = new DecimalFormatter(formatPicture, format);

            return(formatter.Format(value));
        }
All Usage Examples Of System.Xml.Xsl.Runtime.DecimalFormatter::Format