2716 {
2717 bool isCorrectlyRounded = number.Kind == NumberBufferKind.FloatingPoint;
2718 bool bSuppressScientific;
2720 {
2721 case 'C':
2722 case 'c':
2723 if (nMaxDigits < 0)
2724 {
2725 nMaxDigits =
info.CurrencyDecimalDigits;
2726 }
2727 RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
2729 return;
2730 case 'F':
2731 case 'f':
2732 if (nMaxDigits < 0)
2733 {
2734 nMaxDigits =
info.NumberDecimalDigits;
2735 }
2736 RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
2737 if (number.IsNegative)
2738 {
2739 sb.Append(
info.NegativeSign);
2740 }
2741 FormatFixed(ref sb, ref number, nMaxDigits,
null,
info.NumberDecimalSeparator,
null);
2742 return;
2743 case 'N':
2744 case 'n':
2745 if (nMaxDigits < 0)
2746 {
2747 nMaxDigits =
info.NumberDecimalDigits;
2748 }
2749 RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
2751 return;
2752 case 'E':
2753 case 'e':
2754 if (nMaxDigits < 0)
2755 {
2756 nMaxDigits = 6;
2757 }
2758 nMaxDigits++;
2759 RoundNumber(ref number, nMaxDigits, isCorrectlyRounded);
2760 if (number.IsNegative)
2761 {
2762 sb.Append(
info.NegativeSign);
2763 }
2765 return;
2766 case 'G':
2767 case 'g':
2768 bSuppressScientific = false;
2769 if (nMaxDigits < 1)
2770 {
2771 if (number.Kind == NumberBufferKind.Decimal && nMaxDigits == -1)
2772 {
2773 bSuppressScientific = true;
2774 if (number.Digits[0] != 0)
2775 {
2776 goto IL_0189;
2777 }
2778 goto IL_019e;
2779 }
2780 nMaxDigits = number.DigitsCount;
2781 }
2782 RoundNumber(ref number, nMaxDigits, isCorrectlyRounded);
2783 goto IL_0189;
2784 case 'P':
2785 case 'p':
2786 if (nMaxDigits < 0)
2787 {
2788 nMaxDigits =
info.PercentDecimalDigits;
2789 }
2790 number.Scale += 2;
2791 RoundNumber(ref number, number.Scale + nMaxDigits, isCorrectlyRounded);
2793 return;
2794 case 'R':
2795 case 'r':
2796 {
2797 if (number.Kind != NumberBufferKind.FloatingPoint)
2798 {
2799 break;
2800 }
2802 goto case 'G';
2803 }
2804 IL_0189:
2805 if (number.IsNegative)
2806 {
2807 sb.Append(
info.NegativeSign);
2808 }
2809 goto IL_019e;
2810 IL_019e:
2812 return;
2813 }
2814 throw new FormatException(SR.Argument_BadFormatSpecifier);
2815 }
static unsafe void RoundNumber(ref NumberBuffer number, int pos, bool isCorrectlyRounded)
static void FormatCurrency(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
static unsafe void FormatGeneral(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific)
static void FormatNumber(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
static unsafe void FormatScientific(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info, char expChar)
static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, int[] groupDigits, string sDecimal, string sGroup)
static void FormatPercent(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)