From 9159cbe469bf24a123494c750369f98ec07c3652 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sun, 2 May 2021 01:21:12 -0500 Subject: [PATCH] Parse group separator --- src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs | 6 +++++- src/Humanizer/Bytes/ByteSize.cs | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs b/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs index 05a4fa4a1..b4478ba05 100644 --- a/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs +++ b/src/Humanizer.Tests.Shared/Bytes/ParsingTests.cs @@ -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); @@ -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); diff --git a/src/Humanizer/Bytes/ByteSize.cs b/src/Humanizer/Bytes/ByteSize.cs index ca75fbe0c..dc54d5ace 100644 --- a/src/Humanizer/Bytes/ByteSize.cs +++ b/src/Humanizer/Bytes/ByteSize.cs @@ -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