Skip to content

Commit

Permalink
Merge pull request #1114 from YohDeadfall/fix-default-number-format
Browse files Browse the repository at this point in the history
  • Loading branch information
clairernovotny committed Oct 29, 2021
2 parents ee0b9ad + 7f86099 commit aea2bf9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
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")]
[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

0 comments on commit aea2bf9

Please sign in to comment.