Skip to content

Commit

Permalink
Parse group separator
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed May 3, 2021
1 parent 75f96e3 commit 9159cbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ public void TryParse()

[Theory]
[InlineData("2000.01KB", "")] // Invariant
[InlineData("2,000.01KB", "")]
[InlineData("2000.01KB", "en")]
[InlineData("2,000.01KB", "en")]
[InlineData("2000,01KB", "de")]
[InlineData("2.000,01KB", "de")]
public void TryParseWithCultureInfo(string value, string cultureName)
{
var culture = new CultureInfo(cultureName);
Expand All @@ -66,9 +69,10 @@ public void TryParseWithNumberFormatInfo()
var numberFormat = new NumberFormatInfo
{
NumberDecimalSeparator = "_",
NumberGroupSeparator = ";",
};

var value = "2000_01KB";
var value = "2;000_01KB";

Assert.True(ByteSize.TryParse(value, numberFormat, out var resultByteSize));
Assert.Equal(ByteSize.FromKilobytes(2000.01), resultByteSize);
Expand Down
3 changes: 2 additions & 1 deletion src/Humanizer/Bytes/ByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,11 @@ public static bool TryParse(string s, IFormatProvider formatProvider, out ByteSi
// Acquiring culture-specific parsing info
var numberFormat = GetNumberFormatInfo(formatProvider);

const NumberStyles numberStyles = AllowDecimalPoint;
const NumberStyles numberStyles = AllowDecimalPoint | AllowThousands;
var numberSpecialChars = new[]
{
Convert.ToChar(numberFormat.NumberDecimalSeparator),
Convert.ToChar(numberFormat.NumberGroupSeparator),
};

// Setup the result
Expand Down

0 comments on commit 9159cbe

Please sign in to comment.