Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 098c55c

Browse files
committed
Fix AllowThouthands for decimal
1 parent b20eaad commit 098c55c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/ServiceStack.Text/Support/StringSegmentExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ public static decimal ParseDecimal(this StringSegment value, bool allowThousands
393393
{
394394
state = ParseState.TrailingWhite;
395395
}
396+
else if (allowThousands && c == ',')
397+
{
398+
}
396399
else
397400
{
398401
throw new FormatException(BadFormat);

tests/ServiceStack.Text.Tests/Support/StringSegmentParse.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public void Can_parse_decimal()
6969
Assert.That(new StringSegment("2.e2").ParseDecimal(), Is.EqualTo(200m));
7070
//Assert.Throws<FormatException>(() => new StringSegment(".e2").ParseDecimal());
7171

72+
//allow thouthands
73+
Assert.That(new StringSegment("1,234.5678").ParseDecimal(true), Is.EqualTo(1234.5678m));
74+
Assert.Throws<FormatException>(() => new StringSegment(",1234.5678").ParseDecimal(true));
75+
7276
}
7377

7478
[Test]

0 commit comments

Comments
 (0)