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

◆ NumberToString()

static unsafe void System.Globalization.FormatProvider.Number.NumberToString ( ref System::Text::ValueStringBuilder sb,
ref NumberBuffer number,
char format,
int nMaxDigits,
NumberFormatInfo info,
bool isDecimal )
inlinestaticpackage

Definition at line 426 of file FormatProvider.cs.

427 {
428 int num = -1;
429 switch (format)
430 {
431 case 'C':
432 case 'c':
433 num = ((nMaxDigits >= 0) ? nMaxDigits : info.CurrencyDecimalDigits);
434 if (nMaxDigits < 0)
435 {
436 nMaxDigits = info.CurrencyDecimalDigits;
437 }
438 RoundNumber(ref number, number.scale + nMaxDigits);
439 FormatCurrency(ref sb, ref number, num, nMaxDigits, info);
440 break;
441 case 'F':
442 case 'f':
443 if (nMaxDigits < 0)
444 {
445 nMaxDigits = (num = info.NumberDecimalDigits);
446 }
447 else
448 {
449 num = nMaxDigits;
450 }
451 RoundNumber(ref number, number.scale + nMaxDigits);
452 if (number.sign)
453 {
454 sb.Append(info.NegativeSign);
455 }
456 FormatFixed(ref sb, ref number, num, nMaxDigits, info, null, info.NumberDecimalSeparator, null);
457 break;
458 case 'N':
459 case 'n':
460 if (nMaxDigits < 0)
461 {
462 nMaxDigits = (num = info.NumberDecimalDigits);
463 }
464 else
465 {
466 num = nMaxDigits;
467 }
468 RoundNumber(ref number, number.scale + nMaxDigits);
469 FormatNumber(ref sb, ref number, num, nMaxDigits, info);
470 break;
471 case 'E':
472 case 'e':
473 if (nMaxDigits < 0)
474 {
475 nMaxDigits = (num = 6);
476 }
477 else
478 {
479 num = nMaxDigits;
480 }
481 nMaxDigits++;
482 RoundNumber(ref number, nMaxDigits);
483 if (number.sign)
484 {
485 sb.Append(info.NegativeSign);
486 }
487 FormatScientific(ref sb, ref number, num, nMaxDigits, info, format);
488 break;
489 case 'G':
490 case 'g':
491 {
492 bool flag = true;
493 if (nMaxDigits < 1)
494 {
495 if (isDecimal && nMaxDigits == -1)
496 {
497 nMaxDigits = (num = 29);
498 flag = false;
499 }
500 else
501 {
502 nMaxDigits = (num = number.precision);
503 }
504 }
505 else
506 {
507 num = nMaxDigits;
508 }
509 if (flag)
510 {
511 RoundNumber(ref number, nMaxDigits);
512 }
513 else if (isDecimal && *number.digits == '\0')
514 {
515 number.sign = false;
516 }
517 if (number.sign)
518 {
519 sb.Append(info.NegativeSign);
520 }
521 FormatGeneral(ref sb, ref number, num, nMaxDigits, info, (char)(format - 2), !flag);
522 break;
523 }
524 case 'P':
525 case 'p':
526 if (nMaxDigits < 0)
527 {
528 nMaxDigits = (num = info.PercentDecimalDigits);
529 }
530 else
531 {
532 num = nMaxDigits;
533 }
534 number.scale += 2;
535 RoundNumber(ref number, number.scale + nMaxDigits);
536 FormatPercent(ref sb, ref number, num, nMaxDigits, info);
537 break;
538 default:
539 throw new FormatException(System.SR.Argument_BadFormatSpecifier);
540 }
541 }
static unsafe void FormatScientific(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar)
static unsafe void FormatFixed(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, int[] groupDigits, string sDecimal, string sGroup)
static void FormatNumber(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info)
static unsafe void RoundNumber(ref NumberBuffer number, int pos)
static void FormatPercent(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info)
static void FormatCurrency(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info)
static unsafe void FormatGeneral(ref System.Text.ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific)
static string Argument_BadFormatSpecifier
Definition SR.cs:488
Definition SR.cs:7

References System.SR.Argument_BadFormatSpecifier, System.format, System.Globalization.FormatProvider.Number.FormatCurrency(), System.Globalization.FormatProvider.Number.FormatFixed(), System.Globalization.FormatProvider.Number.FormatGeneral(), System.Globalization.FormatProvider.Number.FormatNumber(), System.Globalization.FormatProvider.Number.FormatPercent(), System.Globalization.FormatProvider.Number.FormatScientific(), System.info, and System.Globalization.FormatProvider.Number.RoundNumber().

Referenced by System.Globalization.FormatProvider.FormatBigInteger().