Beispiel #1
0
        public static string ToCurrencyString(this BigDecimal value, int maxDigits, NumberFormatInfo format)
        {
            value.Normalize();

            if (maxDigits < 0)
            {
                maxDigits = format.CurrencyDecimalDigits;
            }

            BigDecimal rounded = value.RoundAwayFromZero(significantDigits: maxDigits);
            var        digits  = rounded.GetDigits(out int exponent);
            var        result  = new StringBuilder();

            NumberFormatting.FormatCurrency(result,
                                            rounded.Mantissa < 0, digits, exponent,
                                            maxDigits: maxDigits, info: format);
            return(result.ToString());
        }
Beispiel #2
0
        public string ToString(string formatSpecifier, IFormatProvider format)
        {
            char fmt = NumberFormatting.ParseFormatSpecifier(formatSpecifier, out int digits);

            if (fmt != 'c' && fmt != 'C')
            {
                throw new NotImplementedException();
            }

            Normalize();
            if (Exponent == 0)
            {
                return(Mantissa.ToString(formatSpecifier, format));
            }

            var numberFormatInfo = NumberFormatInfo.GetInstance(format);

            return(BigDecimalFormatter.ToCurrencyString(this, digits, numberFormatInfo));
        }