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

◆ TryFormatDecimalF()

static bool System.Buffers.Text.Utf8Formatter.TryFormatDecimalF ( ref Number::NumberBuffer number,
Span< byte > destination,
out int bytesWritten,
byte precision )
inlinestaticprivate

Definition at line 490 of file Utf8Formatter.cs.

491 {
492 int scale = number.Scale;
493 ReadOnlySpan<byte> readOnlySpan = number.Digits;
494 int num = (number.IsNegative ? 1 : 0) + ((scale <= 0) ? 1 : scale) + ((precision != 0) ? (precision + 1) : 0);
495 if (destination.Length < num)
496 {
497 bytesWritten = 0;
498 return false;
499 }
500 int i = 0;
501 int num2 = 0;
502 if (number.IsNegative)
503 {
504 destination[num2++] = 45;
505 }
506 if (scale <= 0)
507 {
508 destination[num2++] = 48;
509 }
510 else
511 {
512 for (; i < scale; i++)
513 {
514 byte b = readOnlySpan[i];
515 if (b == 0)
516 {
517 int num3 = scale - i;
518 for (int j = 0; j < num3; j++)
519 {
520 destination[num2++] = 48;
521 }
522 break;
523 }
524 destination[num2++] = b;
525 }
526 }
527 if (precision > 0)
528 {
529 destination[num2++] = 46;
530 int k = 0;
531 if (scale < 0)
532 {
533 int num4 = Math.Min(precision, -scale);
534 for (int l = 0; l < num4; l++)
535 {
536 destination[num2++] = 48;
537 }
538 k += num4;
539 }
540 for (; k < precision; k++)
541 {
542 byte b2 = readOnlySpan[i];
543 if (b2 == 0)
544 {
545 while (k++ < precision)
546 {
547 destination[num2++] = 48;
548 }
549 break;
550 }
551 destination[num2++] = b2;
552 i++;
553 }
554 }
555 bytesWritten = num;
556 return true;
557 }

References System.destination, and System.Math.Min().

Referenced by System.Buffers.Text.Utf8Formatter.TryFormat().