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

◆ TryFormat() [5/16]

static unsafe bool System.Buffers.Text.Utf8Formatter.TryFormat ( decimal value,
Span< byte > destination,
out int bytesWritten,
StandardFormat format = default(StandardFormat) )
inlinestatic

Definition at line 377 of file Utf8Formatter.cs.

378 {
379 if (format.IsDefault)
380 {
381 format = 'G';
382 }
383 switch (format.Symbol)
384 {
385 case 'G':
386 case 'g':
387 {
388 if (format.Precision != byte.MaxValue)
389 {
390 throw new NotSupportedException(SR.Argument_GWithPrecisionNotSupported);
391 }
392 byte* digits3 = stackalloc byte[31];
393 Number.NumberBuffer number3 = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, digits3, 31);
394 Number.DecimalToNumber(ref value, ref number3);
395 if (number3.Digits[0] == 0)
396 {
397 number3.IsNegative = false;
398 }
399 return TryFormatDecimalG(ref number3, destination, out bytesWritten);
400 }
401 case 'F':
402 case 'f':
403 {
404 byte* digits2 = stackalloc byte[31];
405 Number.NumberBuffer number2 = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, digits2, 31);
406 Number.DecimalToNumber(ref value, ref number2);
407 byte b2 = (byte)((format.Precision == byte.MaxValue) ? 2 : format.Precision);
408 Number.RoundNumber(ref number2, number2.Scale + b2, isCorrectlyRounded: false);
409 return TryFormatDecimalF(ref number2, destination, out bytesWritten, b2);
410 }
411 case 'E':
412 case 'e':
413 {
414 byte* digits = stackalloc byte[31];
415 Number.NumberBuffer number = new Number.NumberBuffer(Number.NumberBufferKind.Decimal, digits, 31);
416 Number.DecimalToNumber(ref value, ref number);
417 byte b = (byte)((format.Precision == byte.MaxValue) ? 6 : format.Precision);
418 Number.RoundNumber(ref number, b + 1, isCorrectlyRounded: false);
419 return TryFormatDecimalE(ref number, destination, out bytesWritten, b, (byte)format.Symbol);
420 }
421 default:
422 return FormattingHelpers.TryFormatThrowFormatException(out bytesWritten);
423 }
424 }
static bool TryFormatDecimalE(ref Number.NumberBuffer number, Span< byte > destination, out int bytesWritten, byte precision, byte exponentSymbol)
static bool TryFormatDecimalG(ref Number.NumberBuffer number, Span< byte > destination, out int bytesWritten)
static bool TryFormatDecimalF(ref Number.NumberBuffer number, Span< byte > destination, out int bytesWritten, byte precision)

References System.SR.Argument_GWithPrecisionNotSupported, System.Number.DecimalToNumber(), System.destination, System.Number.NumberBuffer.Digits, System.format, System.Number.RoundNumber(), System.Number.NumberBuffer.Scale, System.Buffers.Text.Utf8Formatter.TryFormatDecimalE(), System.Buffers.Text.Utf8Formatter.TryFormatDecimalF(), System.Buffers.Text.Utf8Formatter.TryFormatDecimalG(), System.Buffers.Text.FormattingHelpers.TryFormatThrowFormatException(), and System.value.