Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Updating NumberToStringFormat to not print the sign if there are no digits being returned #20109

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/System.Private.CoreLib/shared/System/Number.Formatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,8 +1770,8 @@ internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref
}
}
}
if (number.sign && section == 0)

if (number.sign && (section == 0) && (number.scale != 0))
sb.Append(info.NegativeSign);

bool decimalWritten = false;
Expand Down Expand Up @@ -1929,6 +1929,9 @@ internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref
}
}
}

if (number.sign && (section == 0) && (number.scale == 0) && (sb.Length > 0))
sb.Insert(0, info.NegativeSign);
tannergooding marked this conversation as resolved.
Show resolved Hide resolved
}

private static void FormatCurrency(ref ValueStringBuilder sb, ref NumberBuffer number, int nMaxDigits, NumberFormatInfo info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ public void Insert(int index, char value, int count)
_pos += count;
}

public void Insert(int index, string s)
{
int count = s.Length;

if (_pos > (_chars.Length - count))
{
Grow(count);
}

int remaining = _pos - index;
_chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
s.AsSpan().CopyTo(_chars.Slice(index));
_pos += count;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Append(char c)
{
Expand Down