Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed default number format #1114

Merged
merged 4 commits into from Oct 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Humanizer.Tests.Shared/Bytes/ByteRateTests.cs
Expand Up @@ -47,7 +47,7 @@ public void TimeUnitTests(long megabytes, double measurementIntervalSeconds, Tim
}

[Theory]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18.4910856038332 GB/s")]
[InlineData(19854651984, 1, TimeUnit.Second, null, "18.49 GB/s")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. This line isn't present in main.

[InlineData(19854651984, 1, TimeUnit.Second, "#.##", "18.49 GB/s")]
public void FormattedTimeUnitTests(long bytes, int measurementIntervalSeconds, TimeUnit displayInterval, string format, string expectedValue)
{
Expand Down
1 change: 1 addition & 0 deletions src/Humanizer.Tests.Shared/Bytes/ToStringTests.cs
Expand Up @@ -37,6 +37,7 @@ public void ReturnsLargestMetricSuffix()
[Fact]
public void ReturnsDefaultNumberFormat()
{
Assert.Equal("10.5 KB", ByteSize.FromKilobytes(10.501).ToString());
Assert.Equal("10.5 KB", ByteSize.FromKilobytes(10.5).ToString("KB"));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Bytes/ByteSize.cs
Expand Up @@ -228,7 +228,7 @@ public string ToString(IFormatProvider provider)
if (provider == null)
provider = CultureInfo.CurrentCulture;

return string.Format("{0} {1}", LargestWholeNumberValue.ToString(provider), GetLargestWholeNumberSymbol(provider));
return string.Format(provider, "{0:0.##} {1}", LargestWholeNumberValue, GetLargestWholeNumberSymbol(provider));
}

public string ToString(string format)
Expand Down