Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ FormatFixed()

static unsafe void System.Number.FormatFixed ( ref ValueStringBuilder sb,
ref NumberBuffer number,
int nMaxDigits,
int[] groupDigits,
string sDecimal,
string sGroup )
inlinestaticprivate

Definition at line 3170 of file Number.cs.

3171 {
3172 int num = number.Scale;
3173 byte* ptr = number.GetDigitsPointer();
3174 if (num > 0)
3175 {
3176 if (groupDigits != null)
3177 {
3178 int num2 = 0;
3179 int num3 = num;
3180 int num4 = 0;
3181 if (groupDigits.Length != 0)
3182 {
3183 int num5 = groupDigits[num2];
3184 while (num > num5 && groupDigits[num2] != 0)
3185 {
3186 num3 += sGroup.Length;
3187 if (num2 < groupDigits.Length - 1)
3188 {
3189 num2++;
3190 }
3191 num5 += groupDigits[num2];
3192 if (num5 < 0 || num3 < 0)
3193 {
3194 throw new ArgumentOutOfRangeException();
3195 }
3196 }
3197 num4 = ((num5 != 0) ? groupDigits[0] : 0);
3198 }
3199 num2 = 0;
3200 int num6 = 0;
3201 int digitsCount = number.DigitsCount;
3202 int num7 = ((num < digitsCount) ? num : digitsCount);
3203 fixed (char* ptr2 = &MemoryMarshal.GetReference(sb.AppendSpan(num3)))
3204 {
3205 char* ptr3 = ptr2 + num3 - 1;
3206 for (int num8 = num - 1; num8 >= 0; num8--)
3207 {
3208 *(ptr3--) = (char)((num8 < num7) ? ptr[num8] : 48);
3209 if (num4 > 0)
3210 {
3211 num6++;
3212 if (num6 == num4 && num8 != 0)
3213 {
3214 for (int num9 = sGroup.Length - 1; num9 >= 0; num9--)
3215 {
3216 *(ptr3--) = sGroup[num9];
3217 }
3218 if (num2 < groupDigits.Length - 1)
3219 {
3220 num2++;
3221 num4 = groupDigits[num2];
3222 }
3223 num6 = 0;
3224 }
3225 }
3226 }
3227 ptr += num7;
3228 }
3229 }
3230 else
3231 {
3232 do
3233 {
3234 sb.Append((char)((*ptr != 0) ? (*(ptr++)) : 48));
3235 }
3236 while (--num > 0);
3237 }
3238 }
3239 else
3240 {
3241 sb.Append('0');
3242 }
3243 if (nMaxDigits > 0)
3244 {
3245 sb.Append(sDecimal);
3246 if (num < 0 && nMaxDigits > 0)
3247 {
3248 int num10 = Math.Min(-num, nMaxDigits);
3249 sb.Append('0', num10);
3250 num += num10;
3251 nMaxDigits -= num10;
3252 }
3253 while (nMaxDigits > 0)
3254 {
3255 sb.Append((char)((*ptr != 0) ? (*(ptr++)) : 48));
3256 nMaxDigits--;
3257 }
3258 }
3259 }

References System.Math.Min().

Referenced by System.Number.FormatCurrency(), System.Number.FormatNumber(), System.Number.FormatPercent(), and System.Number.NumberToString().